[UE5] No GameInstance in editor

I’m somewhat new to UE and I’ve looked at too many tutorials and can’t find anything on this. I’m creating some dynamic assets (created in C++) when a level loads. I need some global settings when creating the asset. I read that GameInstance remains for the duration of the game, so I derived it and put the settings there. But in the UE editor, the level and world is created before the GameInstance. So when the level is created in the editor, the engine asks my dynamic assets to create itself, but there is no GameInstance to get the config data from.

It works fine when you play in the editor. Just not in the editor itself.

If I want to store some global configuration and data that persists between levels, is there a different class I should be using? Is there a way to force the GameInstance to be created before the level loads in the editor?

While I’m at it, where’s the best place to put per-level data in C++? I’ve been putting stuff in the player character or in the player controller, but it seems odd to me to put level information in the character. I guess I could drop an invisible C++ asset into the level. What’s the best practice?

Check subsystems, perfect fit. They can very well act as managers of stuff.
You can choose at what point it’s lifetime will begin by inheriting one Programming Subsystems | Unreal Engine 4.27 Documentation
image

Ad. 2: What data ? You can just create UObject at desired time to store whatever You’d want, it doesn’t have to be actor.

Cheers !

Thanks! I’ll try an Engine subsystem.

I just tried it and this is perfect! Thanks again! My code is SO much simpler now. I was able to delete a bunch of code that tried to workaround the issue before. Now, it just works.

1 Like