I want to add a save system to my game. Therefore killed enemies should not appear again when I relead the scene. I thought about giving each enemy a specific id and save this when they get killed. OnStart I would then check if the enemy appears in the saved list. What is a more efficient way to save and load the in my scene? Cheers Fabian
What you propose is definitely a valid solution, but there are things you could do to significantly improve performance:
Let's say that you do end up giving each unit a unique ID, and that you end up saving to a file between sessions. That's totally fine, but saving to and reading a file every time you go between scenes in the game or every time you kill an enemy is gonna be slow and inefficient!
If you add a script that goes between scenes (that has DontDestroyOnLoad), which contains a static Hashmap/Dictionary of units that you killed, you can read the data from there every time you reload a scene. Because it's a hash-table, it won't get more inefficient as you add more units, and because it's a simple object that doesn't require you to read and write to a file, you'll be able to do so many times in your game without it affecting performance.
Then, all that's left is whenever your user "saves" the game (assuming you want to keep the state between play sessions), you save to your file the data from your hashmap/dictionary, and whenever a user loads the game you set the data in your hashmap/dictionary based on your file.