Saving in Unity!!
Continuing where the last post ended. The version then lacked most of all was enemies, they where not included when saving. As such it is not an functioning system, but that will be mended.
There are three different enemies in the game and they have different properties that one might want to save, though there are some parts that they share such as position. This would result in a class for each type so they are easily separated and they have their own data. But to start off it would be easiest to start with one class and enemy so there is less to keep track off (less that can go wrong and less to debug) and there is only one type to search for when finding enemies.
A class similar to the characters data class was created but with an added position (the rest was added later, start small to see if it works). The enemies needed a bit more work and control to make sure that all was saved and loaded, and that it was the ones that had been saved that was being loaded. Enemies that had been killed was set as inactive so they could be activated again when the player re-spawned, those that where killed and the player managed to reach a save zone was deleted, since there was no need for them in the game after this point.
Besides adding a position the enemies current state was needed, position so that the enemies appear in the same spot as when the player reached the spawn point (important if the game should seem to return to that state). The enemies need to return to the state they had when saving so that they are not continuing to attack or chase the player, which is not desired. The state does not necessarily need to be saved, a function that resets the state and then letting the logic run its course and reach a conclusion of what it should be doing. The enemy could however be doing something important though unrelated to the player and if letting logic run its course a different conclusion could be reached, resulting in it doing something other than it did before. So using a variable to hold the information about a state seemed better.
The character saving system changed, some parts needed to be added and more options was included. A switch that allows the designer to choose if the player should start with full health or the health value when saving, this would enable testing what works best for our game and/or later add it as a part difficulty level. Quite a simple part but very important, when trying to find what works best.
This is what was implemented for now, more might be implemented later. Some of the parts that is needed are, interact-able objects (so they are in the same state and place as before), same with events that was activated after saving they should not be active when re-spawning so the saving script should have some access to the event handler that is used so it knows what events have been activated and save it.
The saving system is not done until the rest of the game is done since until then it has to update the different parts so that all the needed data is saved and loaded, which will change as the game changes. There is also the balancing with what data actually needs to be saved to a file and what could be reset to a default value in the object, it tends to be useful to have a function that can reset some values.