How to save object variables when the objects are deleted

How can I save a object’s object variables ?
For example let’s say i have a object with variables HP , Atk and speed and in some later event i modify those variables to a different value from what they were initially. Then in some later event i delete the objects and create it back again , is there way to save those changes to object variables that I previously changed so that they still stay with the object when I create them again.
I tried making global variables to save each object variable but it got messy real quick with having like 6 variables each object and saving them per creature.
Maybe if there is a way to do it better pls help.

Short answer: no, not directly.

Long answer:

So keep in mind object variables are just templates of variables for each instance created in the scene. Those instance variables only exist so long as the instance does. If you delete the instance or change scenes, those instance variables are gone.

You could use the save state actions, but that is going to save everything and anything other than the things you have excluded.

Your best bet would be to revisit the global variable setup you had before and try to clean it up to be more usable, most likely using a structure or array variable to track each instance and their variable values.

Just a heads-up: I haven’t tested it for your exact case. I was testing it because I needed it for Custom Objects, but you could try the Variable Copier extension.

It “should” allows you to copy variables between objects. You could create proxy object and then retrieve the variables from there.

If you want to give it a try, you could test it.

If it doesn’t work, you’ll have to do what Silver suggested above and store the values in variables.

However, in my opinion, you should first really make sure that you’re actually forced to delete the object. Maybe you could make it invisible or inactive instead, and then either restore it later or permanently delete it. Copying values/states between objects is something I would avoid in a game unless I’m really forced to.

edit: however to copy a var with the extension you have to put your obj values into a structured or array var

Hmm , i currently just have 6 variables that would only store data for 6 objects but I’m now realising that I have no way to save more than 6 objects and I don’t even know how many there would be.. so pre making the variables just wouldn’t work , is there a way to create variables using actions ?

For that, you’ll have to dive into the Storage and JSON conditions/actions… perhaps even the conversion ones here.

However, I’d like to reiterate that, in my opinion, you’re overcomplicating your project. For what you’re trying to achieve, carefully planning the situation beforehand would help you avoid using extensions or actions that, in general, create more problems than solutions when it comes to debugging, recoding, and so on.

Generally, you create the variable first, even if you don’t use it right away, and then you change its values afterward.

The issue with creating variables before hand is that I don’t know how many are needed , depending on the player it could be just 10 , it could be 50 or even 100. Its not supposed to be limited which is why I need a way to dynamically create variables

If you are using structure variables you can dynamically create child variables within the structure, yesm

The info is in the wiki on the syntax.