Dear all,
Is this a bug in Unity. It’s quit simple. When writing some Script
This for example:
var target = 270.0;
var speed = 10.0;
I apply the script to an object, run the preview and everything’s fine. I stop the preview, go back into the editor and lets say alter the speed variable to 20 but it stay at 10 when I preview it again!!! It’s getting really frustrating. It’s also not updating the values in the Inspector window.
What’s the way to overcome this as I have to delete the script from the object and then re-drag it onto it to update each time. :???:
Kindest Regards,
Jonathan.
It is not a bug, it works like this for variables listed in the inspector. It simply keeps the value listed in the inspector. Useful sometimes, annoying some other times.
If you have a lot of instances of the script with different values you wouldn’t like them to be resetted at every build.
For example would you like unity to reset all gameObjects references you assigned in the editor?
It’s not a bug, it’s an Object Orientation feature. When you attach a script to an object, a copy of it, including its variables, is set to the object. When you edit the script, you’re not editing the copy attached to the object. If you want to change the copy, change the value through the inspector, or place all the changes in the variables inside the Start() function of the script. This function is called in the first frame, and everytime it will be updated with your variable changes.
If you want a technical explanation why fuctions are updated when you edit the scripts but the variables are not, search for Late Binding and Virtual Tables within Object Orientation context
That’s a pretty deceptive feature then. If I select an object in the Hierarchy, go to its property list, and right-click on a script attached to the object, I shouldn’t have “Edit…” as an option if I can’t actually edit the script instance attached to the object.