Save system for all objects in the scene

I know, I know, this has already been discussed more than once. But I don’t understand the algorithm itself. I easily save existing objects on the stage and their variables and load them using structure+json. But when creating new objects, their preservation and subsequent creation at given points is a problem.

The algorithm itself looks like this to me:

  1. All objects need an identifier, which can be assigned immediately after the object is created and stored in its ID variable.
  2. A structure is created (scene variable) in which there can be several fields that record the x,y position, animation, etc.
  3. Everything is saved, added to json and ok.
  4. But when loading, either not all objects are created, or in the wrong places. Although when saving, the action is used - repeat for each object on the scene.

Your concept only works if there’s the same number of objects being loaded as being save.

A different approach would be to put all the objects into an array and save them all at once. You can then load the array and use for each child to add them. You can add any value to the array. I wasn’t sure how you’re using the id. Change whatever you want. This uses a save and load button.

try me: The objects are dragable. Just don’t load before saving. For simplicity there are no checks.

1 Like