- Home /
Variables Not Updating?
I declare and set a variable outside of a fixed update function in Unity 3.1 on Mac OS X. The fixedUpdate function initially shows the correct variable value. However, when I change the value of the variable, it doesn't change in fixedUpdate unless I change the name of the variable too. For example:
var maxYawSpeed:float = 3000.0; function FixedUpdate(){ Debug.Log(maxYawSpeed); }
Outputs: 3000.0
var maxYawSpeed:float = 1000.0; function FixedUpdate(){ Debug.Log(maxYawSpeed); }
Still Outputs: 3000.0
var maxYawSpeed1:float = 1000.0; function FixedUpdate(){ Debug.Log(maxYawSpeed1); }
Now Outputs: 1000.0
Answer by Mike 3 · Nov 26, 2010 at 04:50 PM
The issue is that you're using public variables. The first time unity sees them, it'll serialize the result, then it'll set that value whenever the script is run after that, with the idea that you'll change the value from the inspector
What you can do is either make the variable private (private var maxYawSpeed:float = 3000;) or set the value in the inspector at editor time
Your answer
Follow this Question
Related Questions
Physics behaviour changing with framerate - Is FixedUpdate() actually working properly? 3 Answers
Camera rotate around a moving object: fixedLateUpdate? 1 Answer
Is it possible to create a second FixedUpdate function running at different rate? 2 Answers
Fixed Update Time, Object Stop moving 0 Answers