Why is my GameState reinitialized with each level load?

When I open a new level, my custom GameState is reinitialised.

The same custom GameState is used for the levels.

I don’t understand why GameState is reloaded ??

A class is not an object. The object would contain the data, but the object is not the same, it is a new one.

think of a class liek a cookie template and the objects are the cookies. Two can be colored and flavored differently but they both would look like the same cookie. xD

If you are comming from Unity, there is no DontDestroyOnLoad like behaviour in UE4 that I know of. But you could use stream levels and do it this way.

To transport data from one level to another you could either save it to an .ini file if it are just a few variables and cheating is no problem or you could create a binary that is loaded an populates the GameState data again in the next level.

Here is a huge document on this topic and it really depends on what you wanna do serialization.

Here is also a nice discussion about this topic

Yes… POO rules are not the problem here (and are not a problem :wink: ). The question is only in relation the level persistance of the GameState instance.

Now I know that GameState instance is not persistent. I will see datas saving/loading between levels.

And, at the end of your second link, there is an UE4 guy talking about the new “GameInstance” for levels persistance usage.

And… no, I’m no comming from Unity :wink:

Thanks for help.

Cool thanks for the hint. **GameInstance ** is brand new, not even in the docs. And it allows to manage state for all players in one place. Pretty sweet.