- Home /
How can I undo HideFlags.NotEditable;
I have a gameobject with script, the script has a lock boollean and when true it activates gameObject.hideFlags = HideFlags.NotEditable; But how can I undo this when the user want to be able to select and edit the object/script again?
Or is there another way to make a object unselectable in the scene view (preferable scene view only and still availeble in the inspector)
Found gameObject.hideFlags = (HideFlags)0; but thats not working as it causes an expecting a semicilon error in uniscript.
http://forum.unity3d.com/threads/37956-How-do-I-lock-a-mesh-or-make-it-unselectable
Answer by Bunny83 · May 21, 2012 at 12:32 PM
There is no c-style cast in UnityScript. UnityScript casts most things automatically. Just use:
gameObject.hideFlags = 0;
The HideFlags enum doesn't have a constant for 0 so this is the only way.
public enum HideFlags
{
HideInHierarchy = 1,
HideInInspector = 2,
DontSave = 4,
NotEditable = 8,
HideAndDontSave = 13
}
Setting the hideFlags to 8 has the same effect as HideFlags.NotEditable.
edit
Since the hideflags could include other flags as well, it's better to just affect the flags you want
This will toggle the NotEditable flag, so it can be used to set and reset it:
gameObject.hideFlags ^= HideFlags.NotEditable;
// which is the same as
gameObject.hideFlags = gameObject.hideFlags ^ HideFlags.NotEditable;
This is the xor-operator which is perfect to toggle a single bit in a variable.
To set a certain bit you would do this:
gameObject.hideFlags |= HideFlags.NotEditable;
To reset a certain bit you would do:
gameObject.hideFlags &= ~HideFlags.NotEditable;
// | - bitwise or-operator
// & - bitwise and-operator
// ~ - bitwise negate
Answer by IzzySoft · Nov 06, 2014 at 10:37 AM
Also, in Unity3D version 4.5.5f, the SceneHierarchyView wont refresh, so wont Hide the object right away. If you want to Hide it, you just have to force a refresh like this:
GameObject go = new GameObject( "GameObject" ); DestroyImmediate( go );
:)
Thanks, this was really helpful! still have to do the forced refresh in Unity5