- Home /
Unity event calling function gets nullreferencexception on bool
If I call Change from anywhere else in my code it works it also works if the event system calls it through a button press and if the editor is playing it works but when I hit stop or change anything with this gameobject it throws a null reference error exception. I tried to check for null with a if statement before it changes the value but it still throws the error.
bool[,] redInterupt = new bool[5,25];
public void Change ()
{
redInterupt[0,0] = true; //null reference error this line
}
NullReferenceException: Object reference not set to an instance of an object Controler.Changed () (at Assets/Controler.cs:260) UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:153) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:630)
A Null reference error means that your script is trying to reference an object or component of an object that does not exist, I would need more info to help you
I'm not even sure it's with the script I've been testing and I think it's something with the toggle. The only time I get the null reference error is if the editor is NOT playing. If I hit play the error clears and doesn't come up again until I hit stop. The code works and does what it's supposed to do. I just have a 24 of these cause of having 24 toggles. It makes it hard to know I have errors that actually hinder what I'm doing. @Nose$$anonymous$$ills @OutOfRam