- Home /
Avoid public variable to get overwritten by the Inspector
How to Avoid a public variable to get overwritten by the Inspector?
ADDITIONAL INFO:
I have public variable like so:
public class Bullet{
//it is default 0 in the Inspector
public float Damage;
I do not want to write in
OnEnable(){
Damage=10;
}
}
I have a Manager Object which does: //Called only rarely and not per each time I enable the bullet
For each Bullet object b,
b.SetActive(true);
b.Damage=100;
But I keep getting 0 and not 100; Please Help! I tried: [System.NonSerialized] public float Damage; but didn't work.
Answer by Larry-Dietz · Dec 26, 2017 at 05:49 PM
You can try hiding it from the inspector. Add [HideInInspector] above the definition, and see if that helps. It will let you keep the variable public, but not show up in the inspector.
-Larry
Your answer
Follow this Question
Related Questions
Using [SerializeField] vs public 2 Answers
public script variable in inspector 2 Answers
Can't initialise public vars in Inspector (C#) 2 Answers
Invisible Public Variable in Inspector 5 Answers