- Home /
How do I Save instantiated Bundle to scene ?
how do I save my instantiated objects to my scene . for example i have instantiated "bubblemoon" in my scene how do i go about saving that object to the scene so that it remains in the scene at next run-time.
Thnx, being able to instantiate in edit mode is a quick fix for exactly what i wanted to do, by only firing once with a count, i can make it so any object my player builds is saved to the scene on a GUI button press, thnx again.
Answer by iwaldrop · Dec 20, 2013 at 06:12 AM
If you're talking about doing it magically, it doesn't work that way. What you'd have to do is implement saving functionality. That means that any dynamic elements of the scene that aren't emergent or can not be inferred by other object's states needs to be saved to disk for reloading when the player reenters a given scene. It's quite a task. You must ask yourself several questions before proceeding.
Will there be multiple players, or save-games? Typically, this is true, like in Oblivion or Resident Evil.
Is the player allowed to travel from scene to scene freely, or is it a linear experience? If linear, the task is greatly simplified, because you can discard stale information (like previous scenes) and only save the current one and player inventory and the like. Otherwise if you can travel all over, like in Fallout, you need to save some of the state of the entire world.
Is it multiplayer? If so, each copy of the save game needs to maintain everything for every player for the reasons of preventing cheating, unless you use some checksums to detect altered save game files.
Is the world procedurally generated, like Minecraft? If so, you'll have to save the entire damn world.
Good times, for sure, but very doable if broken down into small chunks of work.
Well basically i am running my entire game in one scene . All that is really need is for the name of my instantiated gameobject to be saved so that whenever the game is next played the name the name will be added to an empty gameobject.
funny i should say that because i know exactly how to do it but i'm considering not having the instantiated gameobject being empty in the first place so saving each name in an array and assigning them to instantiated empty gameobjects is a no no.
I dont think it would be as complex to do in my situation as you make it sound but you are absolutely right if i wasn't just using one scene. the game is single and multiplier but that wont be an issue.
Anyway i'm going to quickly create a function to save and instantiate object with the desired name.
i have decided to add a .txt file to each exported bundle that is to be imported and saved in my scene so . simply saving the name of each instantiated object is no longer an option.
I guess this will be a bit difficult after all.
I didn't mean to make it sound hard or complex; just wanted to convey that developing a solution requires sound analysis of the problem.
It doesn't sound like it should be that difficult in your case if you can serialize a component to disc. That component will simply have an array of custom, serializable, objects that it tracks and then, when loaded, will instantiate n number of GameObjects with the configuration information that's in your custom class. I would stay away from text if I were you, just use a BinaryFomatter. ;)
Answer by supernat · Dec 20, 2013 at 06:19 AM
Funny, someone else just posted that their objects were staying in the editor after they stopped playing. Anyway, you might find something in the Asset Store to do this for you. Otherwise, you can add a script that copies the properties (transform, etc) of the object each frame and monitor the Application.isPlaying property. When it changes state, create a new object with the same name and copy the properties into it.
You need this script to execute in Edit mode (after you exit Play), so add the ExecuteInEditMode attribute: http://docs.unity3d.com/Documentation/ScriptReference/ExecuteInEditMode.html
You would attach this script to the prefabs right after you instantiate them for optimal results (i.e. don't want to run it on all of the objects in the scene).
Your answer
![](https://koobas.hobune.stream/wayback/20220613124530im_/https://answers.unity.com/themes/thub/images/avi.jpg)