Game instance subsystem not initialized during GameInstance Event Init

BioMedKUL
Fri, 11 Aug 2023 12:18:32 +0000
Programming & Scripting

Hey,

I’ve been trying to write a plugin that handles communication with a server. It does so using a GameInstance subsystem. I got everything working, but then I started wondering if I could make the most used function static, so I don’t always have to include the Subsystem node when calling it in blueprints.

To get access to my subsystem’s variables when calling the static function, I call GetSubsystem() and this works. except it throws an error when calling it in the Event Init of the Game Instance. The GetSubsystem call returns null here causing the code to fail.

According to documentation, Game Instance subsystems are initialized as the Game Instance itself is initialized but I would expect this to be done before calling the blueprint’s Event Init.

// ...
UWorld* world = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::Assert);
	UGameInstance* instance = world->GetGameInstance();

	UIASSubsystem* IASSubsystem = instance->GetSubsystem<UIASSubsystem>(); // Returns null
// ...

My question is whether it’s normal practice to try and get my variables in this way (I originally tried using static variables but I was getting Unresolved External Symbol errors when I did that) or how else I should go about using the subsystem’s variables in the static method. And if there is a way to force the initialization of the subsystem before the Game Instance’s Event Init runs.

Thanks in advance!

3 posts - 3 participants