How can I assign data to a level that's readable from anywhere?

Hello!

I’m trying to create a system where each level has a constant set of data that I can access from anywhere, even when the level is not loaded. For example, some levels in our game can have AI players, and some cannot. I need to be able to know in the lobby whether the level can spawn AI’s or not before loading it in order to dynamically show the proper menu options to the player.

Are there any systems in the engine suited for this? Or if not, does anyone have any suggestions for elegant solutions? I’m trying to avoid dirty hacky code, because I need the system to be easily expandable if we add or remove levels from the game as we keep developing. I prefer blueprint solutions, but C++ is fine if there’s no good blueprint solutions.

I would have all this data in the GameInstance.

You create a struct with your level settings, and then create a Map with Key = “LevelName”, Value = “LevelSettings”.

Then you would just create a GetLevelSettings function where you input your level name, and then game instance provides you with the settings for that map.

You end up with a centralized location to set all your level settings by name.

I did consider something like this, but felt it was kind of dirty given that the Game Instance is technically just held in memory during a session. It just doesn’t feel like a particularly robust and scalable solution. I guess it works though, so I’m probably heading down that road if there’s nothing else.

Why not use the SaveGame system?

You can create a SaveGame structure for levels and then create a SaveGame per level to acquire the data. This can be loaded and read at any point, regardless where you are. Data can be updated as well.

but… do you also want to access the data while the game is not running?

If you need to keep data modified during runtime you can just store the array of maps to a SaveGame object and store it in memory.

Now that I’ve allowed some time for more answers and have been thinking it over, I think the game instance solution is the closest to what I want, so I’ll select this thread as the answer.