UE4通过类名符串和函数名字符串调用函数


	UPROPERTY()
	FACTION_DATA CurActionData;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, DisplayName = "播放完成回调类(不要A,U前缀如Actor非AActor)")
	FString ClassName;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, DisplayName = "播放完成回调函数")
	FName CallBackUFunction;
FACTION_DATA CurActionData;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, DisplayName = "播放完成回调类(不要A,U前缀如Actor非AActor)")
	FString ClassName;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, DisplayName = "播放完成回调函数")
	FName CallBackUFunction;

if (!ClassName.IsEmpty())
	{
		UObject* ClassPackage = ANY_PACKAGE;

		UClass* Result = FindObject(ClassPackage, *ClassName);
		//动画结束回调
		if (Result && (!CallBackUFunction.IsNone()))
		{
			UFunction*CallBack = Result->FindFunctionByName(CallBackUFunction);
			if (CallBack)
			{
				ProcessEvent(CallBack, NULL);
			}
		}
	}

 

备注:回调类(不要A,U前缀如Actor非AActor),CallBackUFunction为Class中的UFUNCTION()函数

如类

UCLASS()
class TEST_API AZombieMonster :public:APawn
{
	GENERATED_BODY()
public:
	UFUNCTION()
	void OnAnimEnd();
}

 

传入值 ClassName=FString("ZombieMonster"),不带前缀A AZombieMonster

传入值 CallBackUFunction=FName("OnAnimEnd");

最终会调用AZombieMonster::OnAnimEnd()函数

你可能感兴趣的:(C++,UE4学习)