I’ve updated this resource for better reliability, handling of multiple scenes and instanced objects.
Run the save and load controllers from game_state.py to save/load the gameUse module mode rather than script mode (see the existing controllers on Cube)
To save/load all scenes, set a property called “all_scenes” to True.
To restrict saving to certain objects, give them a unique property, and set a string
property on the saving object (Cube) called “save_property” to the property name.
To omit objects from being saved, give them a unique property, and set a string
property on the saving object (Cube) called “ignore_property” to the property name.
Deleting this property from the Cube will restore global behaviour.
Instances will be saved and loaded by deleting any instances of the saved object base
object (from the hidden layer) and then re-spawning the instances as required
by the save file.
In this example, I don’t want to save any properties on the saving object (Cube)
in case we set save-configuration properties during the game -they’d be overwritten
The script saves the following information:
- Transforms (position, orientation) in local space (to correctly deal with parenting).
- Dynamics (velocity, angular velocity), again in local space.
- Logic state
It supports instances and static objects (referring to objects that originate from the main layer).
Any instances created from an instance which is saved in a save file are deleted when loading that file back, even if they are not specifically referenced in that file (due to non-unique identifiers)
File - save_load.blend (668 KB)