- Home /
Script object creation that persists
Hello everybody, hope you re doing well :).
This is probably a question with a simple answer. I was trying to figure out how to keep objects that are created through a script in the editor after the game run has stopped.
So say i want to instantiate 50 objects each of which are 50 units away from each other in some axis for my level. Doing this by hand sounds tedious so i make a script to create those. How can i keep them on the editor after the game has stopped so that i can fiddle with them manually afterwards?
Thank you all for reading my question. Have a nice one
Answer by robertbu · Mar 16, 2014 at 06:44 AM
The 'right' answer is write an editor script:
http://docs.unity3d.com/Documentation/Components/ExtendingTheEditor.html
But there is a hack. While running, you can copy the objects in the hierarchy to the clipboard. Then once you've stopped the app, you can paste those objects into the hierarchy.
Thank you, this is what i was looking for.
P.S: $$anonymous$$ost likely you won't know but is the hack approach safe to use?
when you copy the objects, stop and then paste them the objects become a part of your scene file
it is a nice shortcut and is much easier than an editor script. it remains really clean because you control when and what to add ins$$anonymous$$d of relying on a script that has to be called by the editor at a very difficult to deter$$anonymous$$e time
with an editor script you have to write your code really clean so that the object's don't get generated every time you open unity and so that they don't cause memory leaks in the editor
Your answer
Follow this Question
Related Questions
Detecting if the 2D Mode button was pressed 2 Answers
Better way to call function from another script from editor script? 1 Answer
Can I write a script to rename objects as I create them? 1 Answer
C# Singleton destructor not called in Editor 1 Answer
How can i convert a prefab instance to an ordinary game object? 2 Answers