06/19/2021
UE4 自带的全局变量,可以在任何时候使用,所以很方便,而且全局变量中涉及到一些重要函数可以辅助学习UE4引擎。CoreGlobals.cpp 声明很多全局变量
GEngine
Print on Screen 打印消息到游戏视图窗口
GEngine->AddOnDebugScreenMessage(); //第一个上手的函数
GetWorld/GetWorldContext
World 分为很多种类,比如PIE,Editor,和Game
GEngine->GetWorldContexts(); //获得数组
GEngine->GetWorldContextFromWorld(GetWorld());
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Red, FString("WorldContext Number: ") + FString::FromInt(GEngine->GetWorldContexts().Num()));
//GWorld
UWorld* PIEWorld =nullptr;
for (auto x : GEngine->GetWorldContexts())
{
//PIE Travel
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::FromInt((int64)x.WorldType.GetValue()));
if ((int64)x.WorldType.GetValue()==3|| (int64)x.WorldType.GetValue() == 1)
{
PIEWorld = x.World();
}
}
- WorldContext很重要的原因:描述一个世界的基本信息,和去下一张图的基础信息,比如URL,GameViewport,OwningGameInstance,Thi