Is there a way to Instantiate Prefabs so that they will stay in the editor after you stop playing?
I want to populate tiles with tree and rock prefabs, and use the tiles again later.
Is there a way to Instantiate Prefabs so that they will stay in the editor after you stop playing?
I want to populate tiles with tree and rock prefabs, and use the tiles again later.
There is a flag called executeineditmode or something similar that you could use to make stuff happen in the editor
Hmm, so I could essentially make an editor tool using this that would instantiate prefabs by scripting, then they would be in the editor just as if I had manually created them?
If so, that sounds like just what I need…
I do it in a different way. I’ve got a game object in the world with a script on it which has arrays of game objects (public vars assigned in the editor) which I use for prefab instantiation. So I just instance directly from the prefab list. I’m importing object id, position, and rotation from maya and using that data to instantiate objects in the game world through a custom editor menu.
Create a script in assets/editor and do something like the following
@MenuItem ("MyTools/Import from file")
static function MyTools_Import () {
// do the importing of the file then instantiate objects
var instance : GameObject = Instantiate(objectList[id], position, Quaternion.identity);
}
There’s all kinds of things you can do with editor scripts, but I’ve barely scratched the surface.
I’m actually having some issues with this method though because it seems to create a different kind of instance than when you drag a prefab into the world. Prefabs you drag into the world are blue in color in the hierarchy and have a connection back to the original prefab. Ex: You change some properties on a script on the source prefab and they’ll change on all objects in the world. However, my the instances are coming in as clones with (Clone) after the name, the name is black in the hierarchy indicating that it has no prefab master, and when changing properties on the original prefab they do not update on all the clones.
Update: I found my solution. EditorUtility.InstantiatePrefab … Instantiates the given prefab. Then you just move it in place and rotate it. Keeps the prefab connection, name is blue and no (Clone).