UE4 C++碰撞检测(OnHit)

来源:互联网 发布:蓝牙虚拟串口软件 编辑:程序博客网 时间:2024/05/17 08:51

H头文件中

    UFUNCTION()        void YourFunction(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit);

CPP文件中

Box->OnComponentHit.AddDynamic(this, &AMyActor::YourFunction);
void AMyActor::YourFunction(UPrimitiveComponent * HitComponent, AActor * OtherActor, UPrimitiveComponent * OtherComponent, FVector NormalImpulse, const FHitResult & Hit){    GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, Hit.GetActor()->GetName());}

如果没实现碰撞功能则设置,物体碰撞类型为挡住所有物体

    Box->SetCollisionProfileName(TEXT("BlackAll"));

可参考我的另一篇文章碰撞检测(Overlap)

原创粉丝点击