- Home /
How to hide parent in Hierarchy and maintain child?
Hi all,
Ive been doing some research on hiding objects in the Hierarchy IDE, which now works fine as long as the object doesnt have a hierarchy of its own.
In another words, lets say I have an Object Tree, which have a child Leaf. Aside from that, lets say I have some Light at the scene. In this case, if I choose Light, I want everything else to be hiden, which is working at the moment. If I choose Leaf, then both the Leaf AND the Tree gets displayed, which is not what I would expect. If I choose Tree, then both the Tree AND the Leaf gets hidden, which also is not working properly. The proper way of it to work would be to hide everything that is not what I selected.
This is what my code looks like:
public static void HideObjects<T>( int choice )
{
object[] allObjects = FindObjectsOfTypeAll(typeof(GameObject));
foreach(object currObj in allObjects )
{
GameObject currGo = (GameObject) currObj;
Component[] listOfComponents = currGo.GetComponentsInChildren (typeof(Component));
for( int i = 0; i < listOfComponents.Length; i++ )
{
currGo.hideFlags = HideFlags.HideInHierarchy;
if ( listOfComponents[i].GetType () == typeof(T) && mouseSelected == choice )
currGo.hideFlags = HideFlags.None;
else
currGo.hideFlags = HideFlags.HideInHierarchy;
}
currGo.SetActive (false);
currGo.SetActive (true);
}
}
What else can I do here in order to hide only a specific object even though this object is in an hierarchy? How to hide a parent without hiding its child or how to hide a child without hiding its parent?
Thank you all!
Depends on what you mean by hiding... but you could disable the renderer component of the object(s) you wish to hide
In your description you mention you can't show something while hiding it's parent or hide something while showing its child. That makes sense to me actually. If I want to see a leaf, of course the parent tree will need to be visible as well (a child is never visible if it's parent is not).
The last question you ask, hiding a child without hiding it's parent, SHOULD be possible but I'm not sure if you tried that.
@PouletFrit, I still want to render it. By hiding I mean to only hide its name in Hierarchy IDE, much like what you get when you do a search in Hierarchy ID$$anonymous$$
@Ivov$$anonymous$$arel, Im actually pretty new to Unity, so I really cant think of a different approach then the one tried here.