How to keep script variables and inspector synchronized?

Hi,

I am very new to unity. Although I tried google a lot I cannot find the answer to this question:

I created a script that contains a public variable like this:

var myvar:int = 6;

The inspector shows myvar and the value 6. So far, so good.

Now I modify the script to:

var myvar:int = 8;

In the inspector there is still the old value “6” shown. Also the script uses “6” when running. The modification in the script is completely ignored.

Vice versa, if I modify the value to “10” in the inspector, the script keeps the old value although it works with the new value that is shown in inspector.

Is there a way to keep script and inspector synchronized so they show the same values all the time?

The inspector will always be taken in account instead of the script variable. It won’t change the script, simply because one script can be used several times on different game objects, but each game object needs different variable values, so to spare us some time and not duplicate the code, the inspector is used for this purpose.

So, no, you cannot keep them synchronized :slight_smile: