Looking for recomendations on how to store and access metadata for game levels

Godot Version

4.2.1

Question

Setup:

  • The game has a number of levels that can be chosen from at random
  • Each level has some set properties (number of players, team vs ffa, is experimental vs released, etc.)

Goal: When a session begins select one of the levels at random based on a set of criteria. For example select a random level that supports 3 players, is marked as release, and supports ffa.

Question: The basis of my question is how do I accomplish the above.

  • How am I best to store the data for each level?
  • How do I then find all the scenes which are considered levels?
  • How do I then load the data for each level?

I would like to avoid having to have a single location in which all of these things are defined. I would much prefer to be able to define the attributes on the scenes themselves and have some way to then find all relevant scenes and access the data from them.

Thanks in advance for any advice and guidance you can offer, it’s greatly appreciated.

Regards,
Regner

One way to do it would be to make a custom Resource that has fields for level info and additional field to store reference to a scene that would need to be load it. Then all Resources from a folder could be loaded, and then filtered through via array filters

If you actually want to store these informations directly in the levels you would be forced to preload all of them. Depending on the size of your project, the size of the levels and the platform you are running it on, this might not be a good idea.
If you have less than ten fairly small levels and are releasing for PC then this is easily done, otherwise vissas approach is the most sensible one

Id add to their response, that you can use SQLite in godot, as long as it is not developed for mobile, just look in the asset store
if you are developing for mobile the quickest way to filter the level information would be having a dictionary with all the different player counts pointing to arrays that contain the levels compatible with them. Find the list of levels compatible with the players and check it against arrays containing the info on ffa, team, etc. in the format of array ffa = [1, 5, 21, 26, 90], where 1, 5, etc. are with ffa

To control if you havent forgotten any level entries have a ready function in the script containing this data looking sth like this:

const highest_level = 100
func _ready():
 var independant_levels = []
 for array in player_count_dict.values():
   for i in array: if not i in independant_levels:
     independant_levels.append(i)
 var not_found = []
 for i in range(1, highest_level+1): if not i in independant_levels: not_found.append(i)
 if not_found.size() > 0: printerr("did not find levels ", not_found)

To store and load the levels you should put all of them in a single folder like res://levels named [number].tscn and load them from there

1 Like

Thank you both, that all makes a lot of sense. I really do appreciate the guidance.

1 Like