专栏目录:SQTaoger:专栏目录zhuanlan.zhihu.com
UFUNCTION里面标记为Exec宏的函数就可以在控制台调用执行,在UGameInstance的派生类里面这样声明的可以直接调用访问,在其他场景类里面声明的要在UGameInstance的派生类里面重写ProcessConsoleExec方法调用一下才可以在控制台调用。UGameInstance的派生类里面直接定义声明使用
MyGameInstance.h
public:
UFUNCTION(Exec, Category = "Console")
void ConsoleFunction(FString Info);
MyGameInstance.cpp
void UMyGameInstance::ConsoleFunction(FString Info)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, Info);
}
2. 在其他场景类里面声明,在MyGameInstance类里面重写ProcessConsoleExec方法
MyGameInstance.h
public:
/**
* This function handles a console exec sent to the object; it is virtual so 'nexus' objects like
* a player controller can reroute the command to several different objects.
*/
vir