- Home /
How do I make serializefield/public readonly in the inspector, but so that I can still access variables in other scripts?
My problem is, that I cant change my values inside the scripts (It changes but it takes the old value from the inspector). I can only change them, if I do it in the inspector. If i remove the public from my variables, then my game gets broken because I need to access variables from other scripts.
Answer by bobbaluba · Nov 30, 2020 at 03:16 PM
You can either use public properties instead of fields, or you can use the NonSerialized attribute.
public int Foo { get; set; } = 123;
or
[NonSerialized] public int foo = 123;
Your answer
Follow this Question
Related Questions
Create a Serializefield for Object Properties 1 Answer
Avoid public variable to get overwritten by the Inspector 1 Answer
Variables in editor script reset when playing 1 Answer
Accessing variable from a method in another script and gameObject 2 Answers
Sorting a list of GameObjects by accessing their int values 2 Answers