Var have different value in Code and Inspector

So I used .js and have something like this

#pragma strict  

var flower = 500;

then when it’s played, because something doesn’t work as it should be, I took a look at Inspector, and suddenly realized what’s shown was

flower: 800

How? Indeed, I changed flower value many times, and its previous value was 800, and indeed, before, when I changed flower’s value sometimes it felt as if nothing changed, eventho the value changed rather significantly.

I’ve made sure when I changed from MonoDevelop to Editor, the circling circle in bottom right has stopped, and when I realized that value difference, I even reimport my code, but really, it didn’t change. At one point finally it’s changed, but honestly I didn’t even know what changed it, and I have many of var declared just like I declared flower above there…

How could that happen and how I prevent it? Or for public var that appear in inspector, should I changed its default value in Inspector, not in Code? Sorry, I really am a noob…

The value in the script/code is the default value. If the script is attached to a gameobject and further a prefab is created, if you modify that value, changing that value in the future in the script will not reflect in the inspector unless you.

A) Explicitly change it by hand.

B) Reset the values in the inspector that default to the initialized values from the script if available.

The reason for this is serialization(saving object values) in the editor.

You can hit the gear on the prefab in scene and eithe reset(all values go to default) or reset to prefab(what ever the prefab is set to in your assets).

By default unity gives priority to values from inspector. It will not change until you change it programatically.

Initialized will be chnaged in inspector if you change it and after inspector will not update it so be careful.

Thanks