Updated speed variable wont update in unity

Ive that when I update my serialized Move Speed from .001f to .01f it will not update in unity even though ive saved the file in VSCode. How can I fix this?

variableInUnity

Enter new numbers in your inspector. They’re overriding the numbers in your code.

If you want to override the details in your code, put in:
steerSpeed = 1f;
moveSpeed = 0.1f;

In your Start method.

1 Like

This is expected behaviour. When you add a component on a game object, Unity serializes (essentially ‘saves’) the data for that component in the scene (or prefab, if it’s in a prefab). When you change the values in code, it doesn’t matter because Unity will use the values it saved - as it should. If you want the values changed, you need to change it in the inspector because this is the values that Unity saves, not the values from the code.

You can do what @MichaelP suggested, but this will remove the use of any value you specify in the inspector meaning no matter what you put in the inspector, it will not be used.

1 Like

I just wanted to add, the idea to set the value of an exposed variable is to have a default setting, if you change those values in code and add the script to a new object (or remove the script from the object and add it again), you’ll see the default values will change to those you just wrote, just keep in mind what @bixarrio said, those values won’t change on objects that already had the script, but that’s what exposed variables are for, you can change them to whatever you like and test things out in real-time, no need to go back to your IDE all the time.

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

Privacy & Terms