David Dusold
David Dusold

Reputation: 21

UNITY variables no longer updating in inspector

Searching this issue I've seen that many people have had the same problem, but I can't find a good solution or even an explanation of why it happens.

It used to be that when updating a public variable in VScode, then saving and switching back into Unity, the variable would update in the inspector automatically. Now, other changes to my code are automatically compiled (for example if I add a Debug.Log statement) but the variable I set explicitly in the code is not imported into Unity; the old variable will still be used. Resetting the component will correctly update the value, as will closing/reopening Unity.

Auto-refresh is set on in my preferences, and I have uninstalled/reinstalled Unity and VScode. I even completely deleted them and re-downloaded, but I'm still having the same issue.

Does anyone know what causes this issue or how I can fix it?

Thanks in advance.

Upvotes: 2

Views: 2706

Answers (1)

Andreas Winther Moen
Andreas Winther Moen

Reputation: 409

When you mark something as public or with the property [SerializeField] it will be serialized, and will have this value until you change it in the inspector. The purpose of serializing a variable is to tweak its values in the inspector instead of the code. If you still want to set the component to the default script value you can click the cog wheel on the component and reset it.

Upvotes: 1

Related Questions