- Home /
How can I access the 2nd tier of children on a prefab in the Project Folder Window?
I want to access the child of a child of a prefab in the Project Folder Window, but Unity doesn't allow you to.
Here's what I mean...
This is what my prefab looks like in the Hierarchy Window. Notice how I can access "Marker" which is a child of a child of the parent prefab.
Now this is the same prefab in the Project Folder Window: For some reason Unity only lets me view the first tier of the prefab's children, and hence I can't access "Marker".
Is there a reason Unity does this? Because I need to access the lower tiered children to set up dependencies in the inspector window. I understand I could just make everything a tier 1 child, but this would make my objects very unorganized and hard to work with.
Any help with this would be really appreciated!
Answer by chronodm · Oct 07, 2016 at 10:03 PM
Note that you can work around this by selecting an instance of the prefab in the Hierarchy view and selecting "Select Prefab" in the context menu. It's a pain, but it does work.
Not true, you cannot access 2nd level children of a prefab in the project view.
@Harinezumi I didn't say you could access the children in the project view. I said you could work around the fact that you can't access them in the project view by accessing them through the hierarchy view context menu.
create a prefab with three levels of children
create two instances of the prefab
in the hierarchy view, select the lowest-level child of one of the instances
in the hierarchy view, right-click and select "select prefab"
note that the inspector now shows the prefab grandchild, not the instance grandchild
change a property, e.g. the material
note in the scene view that both instances change
Ah, that works? Didn't know that. Thanks for explaining and sorry for reacting too soon.
Answer by alexjolig · Aug 09, 2016 at 09:02 AM
From this post
That is by design - from a scene, you can make references to game objects you can see in the project view; the ones nested down one level in a prefab.
We've limited that to one level for a few reasons: - A larger level made by an artist can have many, many game objects inside it. Letting people make references to game objects deep in the hierarchy seemed to be dangerous, as it would be too easy to introduce code dependencies on arbitrary art assets.
In code-based prefabs, its usually more flexible to have some accessor properties in the root game object that has pointers to what you need.
It seems to me that allowing deletion of gameobjects directly inside prefabs is actually a bad idea. Don't you want to see what you're doing? (If you are a programmer who has a complex manager setup, you can probably handle it - but prefabs are also used for graphics, and there you want to see what you do anyways)
And also a good offer to solve the issue
Double-clicking a prefab brings to you to a scene view with just that prefab instantiated in the scene hierarchy. So you can see the prefab in 3D, edit whatever you need to, and then when you close out of this view it goes back to whatever level you were previously editing...
"Double-clicking a prefab brings to you to a scene view with just that prefab instantiated in the scene hierarchy" I wonder how many hundreds of people have read your post and excitedly tried that in Unity. I was soo excited and then soo disappointed in such a rapid succession i need a $$anonymous$$ break. d:
I too double clicked and felt great sadness.
C'mon Unity.. let us decide if its dangerous or not to our project. S$$anonymous$$H
Answer by Chris333 · Feb 07, 2015 at 09:48 PM
Hi,
i think the traversing level in the project window is limited by default and you cant change that.
Take a look into this forum post. Maybe someone has a solution for you. http://forum.unity3d.com/threads/showing-deeper-nested-levels-in-prefabs-project-view.8101/
Answer by winxalex · May 16, 2018 at 07:51 PM
[MenuItem("Assets/Tools/WinxProduction/Expand Prefab")]
public static void ExpandPrefab() {
GameObject go = Selection.activeGameObject;
Debug.Log(PrefabUtility.FindPrefabRoot(go));
if (go != null && PrefabUtility.GetPrefabType(go) == PrefabType.Prefab) {
//only first level are shown, so check deeper
foreach (Transform child in go.transform) {
if (child != go.transform) {
child.gameObject.Traverse((gameObject) => gameObject.hideFlags &= (~(HideFlags.HideInHierarchy)));
}
}
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(go), ImportAssetOptions.ForceUpdate);
}
}
[MenuItem("Assets/Tools/WinxProduction/Collaps Prefab")]
public static void CollapsPrefab() {
GameObject go = Selection.activeGameObject;
if (go != null && PrefabUtility.GetPrefabType(go) == PrefabType.Prefab) {
//only first level are shown, so check deeper
foreach (Transform child in go.transform) {
if (child != go.transform) {
child.gameObject.Traverse((gameObject) => gameObject.hideFlags |= HideFlags.HideInHierarchy);
}
}
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(go), ImportAssetOptions.ForceUpdate);
}
}
public static class GameObjectExtensions {
public static void Traverse(this GameObject obj,Action<GameObject> action)
{
foreach (Transform child in obj.transform)
{
if(child!=obj.transform){
action(child.gameObject);
Traverse(child.gameObject,action);
}
}
}
}
Above will show you all levels but you wont see the hierarchy. So if you want that https://github.com/robotron2084/phinspector and don't want to create instances(I don't)