- Home /
Unity is not reflecting changes in script
I have tried using both visual studio 2019 (Community) and VS code, but whenever I make changes in a global variable, unity does not reflect that change. I have to reset the script component to reflect the changes. "Auto-refresh" is also checked in the preferences. In previous projects, it was working just fine.
Answer by oboy_gamer · Apr 03, 2020 at 09:40 AM
If you have a variable set to public, it can only be changed through the inspector or at runtime through a script. For instance, if your variable looks like this:
public float variableName = 25f;
it will show up in the inspector in unity. You can then change it in the inspector. But if you try to change the line in your script it‘s value won't change since it can be changed through the inspector. The value in the script is only the default value for new components.
One solution to the problem is to use HideInInspector. For instance:
[HideInInspector] public float variableName = 25f;
This won‘t show up in the inspector and the value will change if you modify the script.
Another solution is to just change it in the inspector instead of changing it in the script.
Your answer
Follow this Question
Related Questions
Referencing Mono Framework assemblies 2 Answers
How can you make an object visible in Unity when you jump on it? 0 Answers
Why does a script launched in Visual Studio from Unity say "Unrecognized Guid Format"? 1 Answer
MacOS Sierra Can't Use pdb2mdb.exe? 0 Answers
Guys i really need your help! Why i cant use unity addons? 0 Answers