Is there a way to make this better?

I have a game with multiple levels that the player can get 1,2,or 3 stars. And Im trying to save the Star per level.

That game instance is telling me the last level played. Each level has a name. And then saving the amount of star the player got.

Is there a better way to do this, im planing on 1000 levels.

Any help is appreciated thanks you

Hey there!

Instead of an Int for each level, I’d make a map of Names to Ints in your SaveGame class. That way you can add new entries to the map based on the level name without having a specific Int variable for each. And if you call the Add function to the Map with a Name that already exists, it will overwrite, so you can always save new data just like with the separate Ints.

Here’s how you create a Map (Simply create a variable, then click the dropdown menu to the right of the Variable’s Type, and select Map)

Then you could structure your logic like this:

More on Maps: Blueprint Maps | Unreal Engine 4.27 Documentation | Epic Developer Community (That’s a 4.27 guide but the information in it is still good)

3 Likes

This worked perfectly, thank you

1 Like