Blueprint GameState variable accessing

Hi,

I hope I can explain this properly.

I have a custom game state, and it worked fine. I then had to add some functionality via blueprints (a custom event). So I added a blueprint implementable function in my header file, and extended the class in Unreal Editor. It all worked fine, but when I set my new blueprint game state as the game state in my project settings a lot of the “old” functionality stopped working. I keep getting error messages about accessing null values in stead of variables. It’s as if my game state constructor doesn’t run. What am I doing wrong?

My issues were not related to me adding blueprints; they were there before, but the blueprints made them visible to me.

I tried to work with the game state fields in its constructor, but the fields are not yet initialized. The lifecycle is explained here: ActorLifecycle. What I needed to do, is to work in the PostInitializeComponents phase, by calling AActor’s PostInitializeComponents() function.

In the header file I had to add:

UFUNCTION()
virtual void PostInitializeComponents() override;

And then do the im-plementation in the .cpp file:

void ABalinanjeGameState::PostInitializeComponents()
{
	Super::PostInitializeComponents();
	// initialization goes here
}

It all works fine now :slight_smile: