- Home /
NullReferenceException after changing the code
I am getting a NullReferenceException every time I change something in my code while the game is running. The exception looks like this:
NullReferenceException: Object reference not set to an instance of an object
MainMenu.Update () (at Assets/Scripts/Menu Handlers/MainMenu.cs:26)
And here is line 26:
void Update() {
settings.tick(); // Line 26
}
The settings variable happens to be null even though I set it like that:
public static Settings settings;
void Start() {
settings = new Settings(mobile);
}
The Settings script does not extend anything
Comment
Answer by Ryuuguu · Feb 01, 2014 at 11:39 AM
It can be done for the correct answer see here http://answers.unity3d.com/questions/629575/how-to-setup-code-so-it-can-recompile-with-null-ex.html
a quick untested guess would be change your code to
public static Settings settings;
void OnEnable() {
settings = new Settings(mobile);
}