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

2023-12-14 19:23:46

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

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);

文章来源:https://blog.csdn.net/boyZhenGui/article/details/134929407
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。