- Home /
public variable not updating (I use HideInspector)
Hi!
I have a variable defined like this:
[HideInInspector]
public int stage = 0;
If I change the value, the scripts still read the value of 0. Is it a bug or I'm doing something wrong?
Have you declared it in a void Update() method of Unity??? or where???
Sorry for the delay guys, I thought I've sent the response, but something must have gone wrong.
So I declare the variable as a member of my class like this:
public class $$anonymous$$achine : $$anonymous$$onoBehaviour {
...
public int stage = 0;
...
}
Than I change the variable like this in the code, than run it again:
public class $$anonymous$$achine : $$anonymous$$onoBehaviour {
...
public int stage = 5;
...
}
After the build unity thinks it's still 0, just like when you don't use HideInINspector annotation.
Answer by steakpinball · Mar 17, 2015 at 09:07 PM
It sounds like the value is still getting serialized. HideInInspector
simply prevents the field from appearing in the inspector. Unity still saves the value. Either show the variable in the inspector or use [System.NonSerialized]
to prevent serialization.