17
« Last post by jeanfabre on December 04, 2024, 01:03:25 AM »
Hi,
This is a common need for games, yet not a trivial feature to develop. Let me describe what you need to achieve that.
- you need a way to identify each object's item in the scene you load levels using an ID as a string. You could do it using the name of the GameObject, as long as you make sure that there are no two of these objects named the same
- theses items must save their status in a persistent way (inside playerprefs most likely). For example an enemy was killed, if you restart that level, the enemy should not be there anymore.
- during the loading of a scene level, each of these items, check the prefs to update their current status and must act accordingly before the game or level can start.
ok, the above seems doable, and it is infact not that hard to make a proof of concept for a couple of items, but the problem will grow as your game grow, and you'll have shortcomings such as:
- bloated playerprefs where you have many many entries, one for each of your items, for each levels. it quicky reaches hundreds of hundreds on a finished game.
- performances will suffer during level loading if dozens of items are each accessing the playerprefs, same on saving a current level progress.
if your game is fairly small in size, the above will do fine, if you have 10 levels with dozens of ennemies, and dozens of pickup items, and collectibles, etc... then it's not going to cut it...
ArrayMaker is a good solution to solve this.
- you can have a dictionnary of each items as keys, and their status as value, so during the gameloop you only access arraymaker, which is fast, and when you need to save, you can use EasySave ( arraymaker has support for easysave) to save in one call your level progress. Same with loading a level, you have one fsm that will read one playerpref entry which represent the state of your level. then each item in that level will check their status using that fsm, instead of accessing the playerprefs themselves.
Let me know if that makes sense.
Bye,
Jean