SerializedField Not Updating in Editor

When I wrote the script for this lesson I followed what was written in the video when creating my variables, so I had:

[SerializeField] int MaxHits;

Then I decided to change it to set the MaxHits variable within the code (like we have in the past) so I updated it to:

[SerializeField] int MaxHits = 2;

I swear in the past when I’ve done this and then go back to the editor the variable would have automatically updated to have a value of 2 when I click on one of my Block game objects, but all of them were still set to 0. The only way I could get them to update was to either go into each one and change them or go into the Prefab and then it’s value.

Am I just misremembering about that value updating in the editor once the object has been created (in the editor)? Or has anyone else noticed this functionality changing? I know I did recently change from version 2019.3.9f1 to 2019.3.13f1, so maybe that made this change?

Any help would be appreciated, because I feel like I’m going crazy right now :slight_smile:

Hi Tom,

I’ve been using Unity since Unity 4, and it has always been this way: When you assign a script to the Inspector of a game object, Unity creates a component/object with the default values from your code. If you change the values in your code, the values in the component do not get updated. The Inspector overrides the values of the object.

Weird, I must just be going crazy then. Thanks!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms