Best way to store/access information about a level?

I’m trying to figure out the most efficient way to store information about a level (name, description, thumbnail, high score, etc) so that I’m able to access and update it throughout the game.

  • Currently I have a “LevelInfo” struct created that contains a number of variables.
  • I create a LevelInfo array in the Game Instance and fill that in (say what the level file is called, give it a text name/description).
  • Placed in each level is an actor (which I use Get All Actors of Class to reference) that contains an integer defining the level’s index in the array (I set this manually myself).
  • Whenever I want to know something about the level like its name or current high score (so I can display it on UI), I’ll cast to the Game Instance and get the LevelInfo array. Using the index from the actor means I can get the specific array index I need.
  • If I want to change the high score for a certain level, I’ll get the LevelInfo array from a SaveGame, edit it, then save the SaveGame (I haven’t set this up yet but fingers crossed it works).

I just thought I’d pop a message on here to see if anyone else has better ideas, as currently it feels a bit messy.

Thanks!

I’m not an amazing programmer, but it seems like what you’re doing is good.

To my knowledge, you can’t communicate directly with the level blueprint, so even if you stored all this info directly on there, you wouldn’t be able to get it

Instead of giving each level a unique index, you could just use the level name instead. You could have an array of all your level names, then when the level loads, use GetLevelName to identify it. Then you would be able to remove that actor from each level

Game instance is the best place for save game stuff, because it’s useable in many places.

The only other things I’d recommend are:

  1. Set up a time to write the variable to the save game every 5 seconds or so. That way, you don’t need to do it elsewhere.

  2. Think about using blueprint interfaces to talk to the game instance. That way, you don’t have to keep casting.

Is saving the save game every 5 or so seconds an ok thing to do? I was under the impression you want to only save when necessary as to not affect performance.

I’ll have a play around with interfaces and see if I can talk to the game instance that way, that sounds like a good idea!

Unless you’re saving a HUGE amount of data, you can save every second honestly.

Take a look at the size of your save game, it’s about 1k, or something like that.

The only difficult part of using the game instance with an interface, is that you have to tell it which part of the save game to update.

Apart from that, it’s great.