- Home /
Are inspector values supposed to override [HideInInspector] code?
One of my bools was getting assigned to true even though I'm initializing it to false, and even though I'm never assigning it anywhere in my code. I need it to be public, but not visible in the inspector, so I'm using [HideInInspector]. After a lot of frustration I realized that I had to make it visible in the inspector, change the value to false in the inspector (where it was set to true), go back to my code and again hide it in the inspector.
So [HideInInspector] quite literally hides variables in the inspector, but the inspector still has the final decision on it's values? That sounds absolutely insane. Is this a bug or a feature?
Answer by Kishotta · Jul 05, 2017 at 01:38 AM
I would imagine that when you added the script the first time, and the variable was visible in the inspector, the variable was set to true
. The object was then serialized, and that value stuck, even after you hid it.
If you'd removed and re-added the component to the gameobject, initialization should have been redone.