- Home /
Cant hide anything in Hierarchy IDE
Hello!
Im currently trying to hide a few objects at Hierarchy IDE and after searching in the documentation, I found this link (http://docs.unity3d.com/ScriptReference/HideFlags.HideInHierarchy.html) which should solve my problem, but after a couple of tries, I still cant manage to hide anything!
This is the code im using to attempt to hide a predetermined object:
public static void HideObjects( bool isTheSameObject )
{
ColorPicker[] getObjects = GameObject.FindObjectsOfType(typeof(ColorPicker)) as ColorPicker[];
for (int i = 0; i < getObjects.Length; i++)
{
Debug.Log ("Object Name: "+getObjects[i].name+". HideFlags: "+getObjects[i].hideFlags);
if (isTheSameObject)
{
getObjects [i].hideFlags = HideFlags.HideInHierarchy;
}
}
}
The Log tells me that the list is in fact getting the right objects. This method is being called at OnGUI by a script extended by EditorWindow.
What am I doing wrong?
Thank you so much for your help!
Answer by Graham-Dunnett · Jun 05, 2014 at 03:55 PM
In a completely new project, with a game object in the hierarchy called "fred" this code works for me:
// c# example
using UnityEditor;
using UnityEngine;
public class Hider : MonoBehaviour {
[MenuItem ("MyMenu/Do Something")]
static void DoSomething () {
foreach (GameObject go in Selection.gameObjects) {
Debug.Log(go.name);
if (go.name == "fred") {
go.hideFlags = HideFlags.HideInHierarchy;
}
}
}
[MenuItem ("MyMenu/Do Something2")]
static void DoSomething2 () {
GameObject fred = GameObject.Find("fred");
if (fred) {
Debug.Log("found fred");
fred.hideFlags = HideFlags.None;
}
}
}
The first menu item looks at the selection and if it finds fred hides it. The second just makes sure it's visible.
This is really weird.. Im still not able to hide it from the ID$$anonymous$$ I manually select a component at the Hierarchy $$anonymous$$enu, click on $$anonymous$$y$$anonymous$$enu, then on Do Something and it still wont hide it even though the Log tells me that the " if (go.name == "fred")" line is getting a hit.
Just for the record, I didnt paste it onto a new project, but on the one im using atm.
Im using Unity 4.3.1f1 and Windows 7.
Any idea what this could be?
I finally managed to do it! In order to make your code work, I had to do the following modification:
if (go.name == "fred")
{
Debug.Log ("Hiding fred");
go.hideFlags = HideFlags.HideInHierarchy;
go.SetActive (false);
go.SetActive (true);
}
Without that, the HideInHierarchy flag wont work at all. Ill still make this as correct answer tho! Thank you!
Answer by sarusian · Jun 05, 2014 at 03:37 PM
You could use visual studio(which I use), it has a lot more features, and allows you to hide entire methods, there is a free version on the website. http://www.visualstudio.com/
Not sure this is any kind of answer for the question. The OP is trying to use a Unity API to hide assets in the hierarchy.
Your answer
Follow this Question
Related Questions
How to hide parent in Hierarchy and maintain child? 0 Answers
Unity hideflags - hide in hierarchy but still render in scene 1 Answer
Hierarchy in editor 2 Answers
Objects in hearachy change order for no reason 7 Answers
Create Multiple Foldouts. 1 Answer