[UE4]设置和获取GameInstance的方式:SetGameInstance,GetGameInstance

SetGameInstance

和设置GameMode一样,

编辑器设置:Project Settings -》 Maps & Modes -》 Game Instance -》 Game Instance Class

 

 

GetGameInstance

新版API:

if (GetGameInstance())
{
	MyGameInstance* GI = Cast<MyGameInstance>(GetGameInstance());
}

 GetGameInstance()是一个全局函数,定义在World.h中。

旧版(新版UE4中下列方式已经无效):

if (GEngine->GetWorld() != nullptr && GEngine->GetWorld()->GetGameInstance() != nullptr)
{
	gameInstance = Cast<UClientGameInstance>(GEngine->GetWorld()->GetGameInstance());
}

 

 

 

猜你喜欢

转载自aigo.iteye.com/blog/2285118