Search Unity

HideFlags.HideInHierarchy not working / broken?

Discussion in 'Scripting' started by RyFridge, Aug 27, 2016.

  1. RyFridge

    RyFridge

    Joined:
    Apr 7, 2014
    Posts:
    52
    Hey!

    HideFlags are not working in Edit Mode with my [ExecuteInEditMode] script correctly. This is my code:
    Code (CSharp):
    1. // for hiding
    2. MyGameObject.gameObject.hideFlags = MyGameObject.gameObject.hideFlags | HideFlags.HideInHierarchy;
    3. // for unhiding
    4. MyGameObject.gameObject.hideFlags = MyGameObject.gameObject.hideFlags & ~HideFlags.HideInHierarchy;
    In Unity 5.0.0, everything is fine, MyGameObject is hidden when it should be, and unhidden the same way.
    In Unity 5.4.0 however, there are the strangest bugs. Sometimes nothing happens. Sometimes when I click inside the Hierarchy after something is being hidden, there are duplicates of the GameObject and other, non-affected GameObjects are missing, until I unhide the original GameObject, and everything goes back to normal.

    I am working on an Editor extension which I created in 5.0.0, and I am about to release, so I really need to know what I am doing wrong here :( Any ideas?
     
    Last edited: Aug 28, 2016
  2. RyFridge

    RyFridge

    Joined:
    Apr 7, 2014
    Posts:
    52
    Okay, I think I found some buggy workaround, but there must be something better?

    I am just having an Update() method that is allowed to switch all GameObjects that can have their HideInHierarchy changed "off and on again" whenever any of them have a change in HideInHierarchy. This can not be what it is supposed to work like.. :p

    Code (CSharp):
    1. void Update(){
    2.     if (!hiddenStateChanged) {
    3.         return;
    4.     }
    5.  
    6.     Debug.Log ("editor update");
    7.  
    8.     for (int i = 0; i < list.Count; i++) {
    9.         if (list [i].objectType == Slot.ObjectType.Gameobject) {
    10.             if (list [i].isHidden) {
    11.                 list [i].obj.hideFlags = list [i].obj.hideFlags | HideFlags.HideInHierarchy;
    12.             } else {
    13.                 list [i].obj.hideFlags = list [i].obj.hideFlags & ~HideFlags.HideInHierarchy;
    14.             }
    15.  
    16.             list [i].obj.SetActive (!list [i].obj.activeSelf);
    17.             list [i].obj.SetActive (!list [i].obj.activeSelf);
    18.         }
    19.     }
    20.  
    21.     hiddenStateChanged = false;
    22. }