69 const UObject* worldContextObject =
nullptr,
71 EGetWorldErrorMode errorMode = EGetWorldErrorMode::LogAndReturnNull
78 if (worldContextObject ==
nullptr)
80 if (IsRunningDedicatedServer() || GEngine->GameViewport ==
nullptr)
89 const FWorldContext* worldContext = GEngine->GameViewport
90 ? GEngine->GetWorldContextFromGameViewport(GEngine->GameViewport)
92 const UGameInstance* owningGameInstance = worldContext ? worldContext->OwningGameInstance :
nullptr;
93 return owningGameInstance ? owningGameInstance->GetSubsystem<T>() :
nullptr;
97 for (
auto it = GEngine->GetWorldContexts().CreateConstIterator(); it; ++it)
99 if (T* result = it->OwningGameInstance ? it->OwningGameInstance->GetSubsystem<T>() :
nullptr)
108 if (
const UWorld* world = GEngine->GetWorldFromContextObject(worldContextObject, errorMode))
110 return UGameInstance::GetSubsystem<T>(world->GetGameInstance());
123 T*
Get(
const UObject* worldContext)
125 const UWorld* world = GEngine->GetWorldFromContextObject(worldContext, EGetWorldErrorMode::LogAndReturnNull);
126 APlayerController* controller = world && !world->IsNetMode(NM_DedicatedServer)
127 ? UGameplayStatics::GetPlayerController(worldContext, 0)
129 return controller ? ULocalPlayer::GetSubsystem<T>(controller->GetLocalPlayer()) :
nullptr;