- Home /
Instantiated PreFab selection problem
Hello, I use scripted gameobject generation in UnityEditor like this: GameObject temp = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/media/tiles/Tile.prefab", typeof(GameObject)); GameObject go = (GameObject)GameObject.Instantiate(temp);
It works fine, I'm able to generate many those objects. But I have one problem. This prefab has several child objects in it. Tile.prefab -objectA -objectB -objectC
If I click on this Instantiated object in unity editor it select one of child objects. But if I put same prefab into scene by drag and drop instead of script, when I click on it, it is selected as whole.
Is some solution to fix this problem?
Answer by rutter · Mar 30, 2012 at 06:57 PM
That's pretty typical for the editor, actually. When clicking on objects in the scene view, the editor will try to figure out which specific object you clicked on -- for example, if you click on a particular mesh which happens to be attached to some object which is a child of your prefab, you'll probably get that child object selected rather than the prefab itself.
I'm not sure if there's a good way around that. I suppose you could look for an editor hotkey to select something's parent object -- or code up your own.
But if I put same prefab from project folder to scene, it gets blue color (I think it means it maintain link to prefab) and when I click on it, it is selected as whole. If I use scripted method, it gets black color in scene hierarchy. I dont know what I do different by script.