2

I have added a C# Script to the Main Camera. I defined a variable MyNumber like below -

public int MyNumber = 9;

My problem is when I change the value of the variable; inside the Unity Editor it remains the same. For example if I change the value from 9 to 19 in the C# script file using Monodevelop, the Unity Editor continues to show My Number = 9 instead of 19; unless I reset the script file.

Please check the screenshot: Variable not syncing properly

2

1 Answer 1

5

This is normal behavior. There's no way for the Unity Editor to know if the old value of 9 was purposely changed in the editor from the default found within your C# script. So it plays it safe and assumes it was modified.

It's important to remember that the script initialized value represents a default value. It does not always guarantee the starting value. Case in point, it's updated in the editor.

Sign up to request clarification or add additional context in comments.

2 Comments

A first-class answer, but the huge number of duplicates and clutter in the Unity3D tag is a real problem, unfortunately :/
@JaySoyer So this is the default behavior you are saying. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.