- Home /
How do I store a GameObject?
I want to delete a game object if something happens, but I want to re-add that object when I undo. The mechanism which is the easiest to implement in my situation is storing all the information of the game object in a variable.
Unfortunately, when I destroy the game object using Destroy()
, the variable I see in the inspector shows "Missing (Game Object)".
Like prefabs, I want the game object to not actually act, but I just want to store their information. How do I do this?
Plan B is storing all information of the game object in a string by "encrypting", so that when I re-add it, the game object will be just like its predecessor. This sound too complicated though, as I have to store all the different variables of the game object.
Answer by MakerBen · Sep 15, 2021 at 07:26 PM
If I understand correctly you are trying to implement an "undo" button? Can you describe a bit more about what you are trying to undo? You might be able to do GameObject.SetActive(false) and GameObject.SetActive(true) so the object still exists, but it just doesn't interact with anything
That is a nice option, but will it be okay if there are hundreds of deactivated game objects?
I am making a replica of Baba is You, if that helps. The sprites are all in a grid, and sometimes objects need to be destroyed. Undoing causes them to revive.
Your answer
Follow this Question
Related Questions
Saving an object from script to project? 0 Answers
Log game object's actions 0 Answers
if game object is located at... 1 Answer
Help with GameObject.FindGameObjectsWithTag 1 Answer
Sprite Not Showing after build to .apk Unity 5.4 ?? 1 Answer