Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

HideInInspector tag ins't working as expected- doesn't remove value control in the Editor

Discussion in 'Editor & General Support' started by krupps, Mar 15, 2019.

  1. krupps

    krupps

    Joined:
    Oct 17, 2017
    Posts:
    159
    Problem: If you create a field and change it in the GUI. Then later hide it with "HideInInspector", Unity is still overriding the value with the last value set in the GUI.

    If you have a simple class attached to a Sprite

    Code (CSharp):
    1. public class Monster : MonoBehavior  {
    2.      public float ScoreValue = 0f;
    3. }
    Works fine. Run the game. His score is 0

    Stop the game.

    In the IDE, change the Score to 50.

    Run the game, his score is 50. All is well.

    Stop the game.

    Edit the class in Visual Studio for Mac. Update the class to hide in the Inspector, so we can change this when the class starts back to 0.

    Code (CSharp):
    1. public class Monster : MonoBehavior  {
    2.      [HideInInspector]
    3.      public float ScoreValue = 0f;
    4. }
    Save.Build.Run.

    Notice the Score is still 50.

    The only way to remedy this is by removing the HideInInspector tag, set it to 0, Run it, Stop the game. Go add back the "HideInInspector" annotation and now it works as expected.But probably not. If you set it to 1 it's probably still zero.

    I don't think Unity is updating based on this annotation.