【UE c++】 UE中c++如何使用回调(关卡动画回调为例)

本文使用关卡动画回调为例

1.创建关卡动画

FString assetsPath = "你的路径";
FStringAssetReference sequenceName(assetsPath);

		ULevelSequence* sequenceAsset = Cast<ULevelSequence>(sequenceName.TryLoad());

		ALevelSequenceActor* currentLevelSequenceActor = nullptr;
		ULevelSequencePlayer* sequencePlayer = ULevelSequencePlayer::CreateLevelSequencePlayer(GetWorld(), sequenceAsset, FMovieSceneSequencePlaybackSettings(), currentLevelSequenceActor);

2.在.h文件中创建回调引用和方法

UFUNCTION()
	void OnFinished();
	
	ULevelSequencePlayer* nowLSPlayer = nullptr;

.cpp中的实现

void ALevelSequenceManager::OnFinished()
{
	UE_LOG(LogTemp, Warning, TEXT("Finish结束了"));

}

3.使用回调

		OnFinishedDelegate.BindUFunction(this,STATIC_FUNCTION_FNAME(TEXT("ALevelSequenceItem::OnFinished")));
		sequencePlayer->OnFinished.Add(OnFinishedDelegate);

你可能感兴趣的:(UE5,c++,ue5,游戏引擎)