Save a copy of a gameObject

I’m trying to create a simple save/reload system, where objects of many different types need to be saved.
There are many objects with different scripts, and I need copies of those instances with all their variables in whatever state they had at the time of copying.

Setting a GameObject variable with a gameObject in the scene only makes a reference to that object, not a state copy. (i.e if it gets destroyed or altered, the variable is affected).

pseudocode to show my problem:

GameObject objectReference = find("a gameobject");
GameObject objectCopy = objectReference;
destroy (objectReference);
print(objectCopy); > console prints "null"

How can I store a copy of a gameObject? Am I going to have to write a custom class to store all the possible data in an instance of a gameObject? If I have to do this, would it be possible to use typecasting? This method would be quite a pain :frowning:

PS: using C#

Gameobject is reference type. once u destroy the object source, the copy of reference is also deleted.

hence the value in objectCopy becomes null when destroy is called.

something once destroyed cannot be recreated as the exact same. what you want to store? positions? scripts? or some other component?

Why not disable the object instead of destroying it. So that you can re-enable it later?

or you can serialize the object and save it to local and get that back later on to create similar object (have a look at Unity Serializer for that purpose)