After every move I save my game state to the table.
Then, when I want to undo one move, I compare current and previous state and make changes.
Sometimes I delete objects, and when I made undo I should to recreate it.
After recreate I should to replace old object_id with new object_id in the all saved states.
And now I can recieve next situation :
- Move : remove “instance1” and “instance5”
- Undo : recreate deleted objects, and create new objects :
2.1. “instance1” recreated with instance name “instance5” and replaced all “instance1” with instance “instance5” in all previos state tables
2.2. “instance5” recreated with instance name “instance143” and replace all “instance5” with instance “instance143” in all previos state tables
As result I have no one object (it was “instance1” object), because it was replaced with “instance143”.
Yes, I know that my current architecture is not a perfect , but now in case when unique instance name can fix all I should rewrited many systems for making workarounds.
About workarounds, what you can offer:
A. Using script with property “uniq_id” - bad idea, I have something about 40 unique objects, and will be more. Adding new script to every GO with one field - is really dirty hack. And I will have many go.get/go.set for checking and compare states - it will not to be a clear code.
B. Do not delete objects, just make it invisible - too many regression for my current code, and we have DEF-2220 - bug when performance too bad on windows with disabled spine animation.
For now I try to change my system with hack between p.1 and p.2 where I will replace instance names with temp_name_n in my table and then replace it with real instance names, when object will be created.