- Home /
How could I save all cloned objects in a scene, and load them back up on start?
I've been having trouble figuring out this for weeks now. Lets say I enter a scene and instantiate a block and then leave the scene. How could I make it to where whenever I re-enter the scene, the block i placed earlier will be cloned into the game in the same position?
Please help! :(
Answer by ZeroSumGames · Aug 16, 2013 at 06:41 PM
Well there are a few ways to do this. I think what you're basically looking for is save game functionality. You can save your scene into XML as an abstracted representation.
So let's say you have a block. You define a block in XML like
<BlockList>
<Block>
<X>1</X>
<Y>0</Y>
<Z>2</Z>
</Block>
</BlockList>
So you would need a class that defines a Block with an X, Y, Z position. You also need a class that can write this data to XML and read it back again. Then when you open your level, you read your XML file and instantiate the blocks where you want them to be.
I'm a noob with Unity, for I only got it a few weeks ago... Could you give me a example on how to do this? Once again, I'm pretty new to the unity environment.
Read this thoroughly. I understand being new at this. The best thing you can learn right now is which questions to ask, which you're doing just fine at. But once you know, ask google first;)
The concept you are after is X$$anonymous$$L Serialization http://wiki.unity3d.com/index.php?title=Saving_and_Loading_Data:_XmlSerializer
Your answer
Follow this Question
Related Questions
Instantiate Reference Problem 1 Answer
Cloning Objects with Instantiate() - variables/references for added Components not stored? 3 Answers
How to Parent a Cloned Object to Another Cloned Object 1 Answer
Instantiate Clones Itself - Rather than Prefab 0 Answers
Destroy a specific instantiated clone? 2 Answers