UE4在C++中使用OnComponentBeginOverlap之類的時間


首先說明一下,官方文檔是錯的,在4.10版本下,綁定函數在角色類的構造函數中不起作用。2016.2.12

這里角色類為例

首先在頭文件中添加:

UFUNCTION()
void OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

OnOverlapBegin為自己定義的碰撞函數

 

然后在Cpp文件中的SetupPlayerInputComponent函數中添加綁定函數:

StartCollectionSphere->OnComponentBeginOverlap.AddDynamic(this, &AThirdPersonCharacter::OnOverlapBegin);

StartCollectionSphere自己定義的USphereComponent。AThirdPersonCharacter為角色類。

 

之后添加碰撞函數的定義

void AThirdPersonCharacter::OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
  GEngine->AddOnScreenDebugMessage(0, 1.0f, FColor::Red, TEXT("!!!!!!"));
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM