- Home /
Instantiate prefabs before runtime, inside editor
Hello! How do I instantiate prefabs so I can interract with them in the editor, without the game running? Instantiating prefabs is not the problem, but to do it once to create a map for the editor is what I need some help with.
I have searched for this online without any good results, so hopefully someone here knows a good way to do this :)
Thanks in advance.
EDIT
I know that I can simply drag a prefab to my editor. Say I want a 10x10x10 cube made up from smaller same-sized cubes. Instead of dragging in 1000 prefabs att an exact location, I want to add them from script, something like this:
for(int i1=0;i1<10;i++){
for(int i2=0;i2<10;i2++){
for(int i3=0;i3<10;i3++){
InstantiateIntoEditorBeforeRuntime(Resources.Load("myPrefab"), Vector3(i1,i2,i3));
}
}
}
(something like that)
If I understand what you're trying to do, just drag the the prefab in to the scene.
Sry for not explaining enough, I have edited my question :)
Answer by m4c0 · Mar 12, 2015 at 06:39 PM
Use PrefabUtility.InstantiatePrefab to do the instantiation. The manual page have an example similar to what you need (add three inlined loops and you are done).
IMHO, a 10x10x10 cube of objects will be strange to manage in editor. I wonder if that's really necessary... :)
Yea the 10^3 cubes was just a way of saying it :3
Thanks alot for your help! :D I have been searching for this for some time. :)