- Home /
Unity not allowing variables to change unless the name is changed
Hi everyone. Sorry for the long title but I couldn't think of a shorter way to phrase it. Basically, I made a bunch of variables and gave them very large values, and I got an error so I decreased their values to more reasonable ones.
The problem is, they all only output 0 no matter what I assign the variables to anymore. Let's say the variable is called yachtCost. If I type yachtCost = 10; then the game will run and show me that yachtCost = 0. But if I change the name of the variable everywhere in the file to yachtCosts or something, then the change works fine.
I know I can just work around it, but is there some way I can fix unity to allow me to change the values of the original variable names? Thanks.
Post your code please, as your question makes little sense.
Yeah, We'd need to see your code, We're unable to help you if you haven't posted any type of code.
Answer by Graham-Dunnett · Jun 02, 2014 at 09:57 PM
So, public variables in Unity can get their values from one of two places. Firstly, from your script code, secondly from the editor inspector. The inspector is always assumed to be the "correct" source for the value. When you change the variable name, you're telling the inspector there is a completely new variable, and the inspector gets the value from the script. Since changing the name is annoying, just reset the inspector, and it'll re-read the values from the script. Alternatively if you want the values to always be read from the script and never the inspector, make the variables private.
Thank you! Your answer is greatly appreciated! I tried it out and it works!
Your answer

Follow this Question
Related Questions
A node in a childnode? 1 Answer
Climb animation is glitchy and isnt working properly 0 Answers
UnityEngine has no appropriate version problem 1 Answer
Singletons in music script? 2 Answers
2.5D ledge hang with javascript 0 Answers