UE 4 C++でOnComponentBeginOverlapなどの時間を使う

1219 ワード

まず、公式ドキュメントが間違っており、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("!!!!!!"));
}