Sorry if this is one of those questions that gets asked all the time, but I couldn’t find any threads exactly about this topic nor any tutorials so I’ll go ahead and ask…
I’m writing a point click adventure game. I have a scene for each room. I’m wondering if anybody has any advice on what approach to take for maintaining state between rooms so that, for example, when you come back into room 1 from room 2 you are now standing by the correct door?
EDIT: Also, things like objects that you picked up previously should now be removed from the scene, etc.
Another example might be if you switch away to a cut-scene, when you return to the scene from whence you came you’d want all the characters to still be in the same position they were before the cut-scene.
Should I maintain some kind of singleton state-monitor that stores a location and orientation for each character and persists between scene changes?
However, be aware of any references to objects that you might still be carrying around… these will get destroyed and accessing their game objects will throw exceptions (I think…).
Yeah, I was hoping to avoid the DontDestroyOnLoad approach, since (besides all the headaches) I do actually want the memory to be freed up and so on when you’re not looking at a scene (besides perhaps a minimal position/orientation)
I understand the situation you’re aiming for, but fundamentally you want the memory to persist.
If it’s a point and click adventure game, how much can people actually manipulate? Could you simply save the states of everything in boolean, or enumeration values, and then when the scene begins you have a SceneController for each scene which puts everything in place/state based on these booleans which persist through every scene?
This way you’d only be saving boolean values, and not the transforms/rotations for each scene.
Also, it is common in games like this which have configurable pieces, to not save it when you leave the scene and most is reset when you return.
Thing is, I don’t care about the models and animation status and particle systems and stuff like that - so there is plenty of memory that can be freed up (perhaps I am misunderstanding exactly what DontDestoryOnLoad does though?)
First, you’re not going to be using all that much memory with a state machine for a handful of objects.
Generally when you load a new scene, everything from the previous scene gets trashed. DontDestroyOnLoad overrides this, causing the object and all it’s atrributes to persist through scenes. Things will get really funky however, if you then reload the scene in which you have a Don’tDestroyOnLoad object spawned. Obviously, you’ll then have two persistent objects!
It might be easiest for you to implement a game manager and have it keep track of each object’s state and use it to spawn objects dynamically in each scene, as well as keep track of positional information for your avatar when entering/exiting doors.