I’m wondering if it’s possible to retain a script by storing it using GetComponent()
and then destroying the object. What happens to the script, and could that script be used to replace the equivalent script in a later instance of the object?
When destroying the object, I believe the reference to the script is destroyed as well. Thus, after destroying the object, if you then try to access the variable that contains the script, you’ll probably get a null reference exception.
If not, then in order to pass the data from the ‘saved’ script into a new object, you would need to write a constructor for the class that takes an object of type (it’s class name), and then extracts the data from the given script into itself.
It’s worth a shot. If it works, it seems like a good way to preserve data.