I'm doing some basic experimentation with the engine for a possible future game that would involve some time-warping aspects (e.g. Prince of Persia). Essentially, I want to be able to save the state of a Game Object (in this case, the Player), store it, and then recall it if needed.
I seem to be able to do this with
However, the one problem with this is that as soon as the object is Instantiated, it is activated (all the scripts begin to run) and rendered. I seem to be able to do:
To stop the scripts/movement/etc. However, when I also try to do:
I get an error that there is no renderer attached to Copy_of_Player. (Actually, the exact Debug message says "No renderer attached to Player(Clone)")
This is a top-level Game Object in the hierarchy...it has scripts as well as several meshes. What am I doing wrong?
In addition, if anyone can point out a better way to save the state of a Game Object for later use (I basically want to be able to put all the main components of a level that are within range back to the way they were 5 seconds ago), that would be greatly appreciated.
A naive brute force approach that should work is to create a Memento object (class, struct or even array if you like) that stores just the variables in question.
Something like memento.storeState(Player_Object); and then memento.applyState(Player_Object). If you add more variables that you want saved, you'd have to add them to the memento and its functions, but this should work.
Obviously if you wanted to access variables stored in the transform or anywhere else in the object, you could do that too.
To implement an actual memento pattern, you would in stead have a class representing the state and you would then apply that rather than directly tweaking each variable. The Player_Object would contain an instance of this state as would the memento and the memento's functions would never change they'd just be