1.引擎派生类直接标记调用
Pawns,PlayerController,CheatManagers,GameState,GameInstance,GameMode,Hud,Player Input等派生类中可以直接在方法中使用UFUNCTION(exec)标记,实现方法调用
2.其他类方法调用(Actor,Object等)
Object的派生类中使用UFUNCTION(exec)标记的方法无法被调用,需要通过重写上述引擎派生类的ProcessConsoleExec方法调用Object自身的ProcessConsoleExec才能实现触发
应用场景:需要在UerWidget派生类(MyWidget)中添加自定义命令实现测试需求
通过重写PlayerController的ProcessConsoleExec方法触发Object的ProcessConsoleExec方法,若不重写,只用UFUNCTION(exec)标记MyWidget类中的方法,输入对应命令则不会被执行
APlayerController.h
class ENGINE_API APlayerController : public AController
{
GENERATED_BODY()
public:
virtual bool ProcessConsoleExec(const TCHAR* Cmd, FOutputDevice& Ar, UObject* Executor)override;
}
APlayerController.cpp
bool ProcessConsoleExec(const TCHAR* Cmd, FOutputDevice& Ar, UObject* Executor)
{
bool bHandled = Super::ProcessConsoleExec(Cmd, Ar, Executor);
if( !bHandled)
{
TArray<UObject*>FindWidget;
GetObjectsOfClass(MyWidget::StaticClass(), FindWidget, turn, RF_ClassDefaultObject, EInternalObjectFlags::PendingKill);
for(UObject* widget::FindWidget)
{
MyWidget* _widget = Cast<MyWidget>(widget);
bHandled = _widget->ProcessConsoleExec(Cmd, Ar, Executor);
}
}
return bHandled;
}
MyWidget.h
UFUNCTION(exec)
void Cheat();
|