目前网上的大多数方法都是,在c++中定义一个基类,然后让蓝图去实现或者…
在此提供 另外两种方法
CallFunctionByNameWithArguments
函数名称Foo
,参数xxx
FOutputDeviceNull OutputDeviceNull;
const TCHAR* CmdAndParams = TEXT("Foo XXX")
this->CallFunctionByNameWithArguments(CmdAndParams, OutputDeviceNull, nullptr, true);
不带参数,只需传入函数或者事件名称
FOutputDeviceNull OutputDeviceNull;
this->CallFunctionByNameWithArguments(TEXT("Foo"), OutputDeviceNull, nullptr, true);
TheEvent->Invoke
UFunction* TheEvent = nullptr;
// RoadActor 是一个Actor的实例
for (TFieldIterator<UFunction> Func(RoadActor->GetClass()); Func; ++Func)
{
// MakeRoad 是RoadActor里的一个事件
if (Func->GetName() == "MakeRoad")
{
TheEvent = * Func;
}
}
uint8* Buffer = static_cast<uint8*>(FMemory_Alloca(TheEvent->ParmsSize));
FFrame Frame = FFrame(RoadActor, TheEvent, Buffer);
TheEvent->Invoke(RoadActor, Frame, Buffer);