I have a problem

When I create in my script a new serialized-Field variable and sets its value to some number, in the unity inspector the variable value is 0 and not the number i’ve set it to be, can anyone help me please?

Hi Rom,

When you assign the script to the Inspector, the component in the Inspector is controlled by the Inspector. This means: If you change the initial value of the [SerializeFiled] variable, the Inspector keeps its own value in the component. This behaviour makes sense because if you have hundreds of components, e.g. enemies, with different values, you don’t want to have the values in your components overridden whenever you change something in your code.

If you want to set your component to the default values which are defined in your script/code/class, click the three dots in the component box, then on “Reset values” or “Reset component”. I currently don’t have Unity running but you’ll know what to click.

Did this help?


See also:

Yes it did help!
Thank you!

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

Privacy & Terms