- Home /
Unexplanable NullReferenceException Error
I am trying to make a 2D platformer and it is all working fine for now. However, I came across this random and mysterious error where I can't figure it out. Could someone explain to me why I have it and where is it causing it. I can't show the code since the error does not give the location. Here is the error:
NullReferenceException: Object reference not set to an instance of an object UnityEditor.Graphs.Edge.WakeUp () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/Edge.cs:114) UnityEditor.Graphs.Graph.DoWakeUpEdges (System.Collections.Generic.List`1[T] inEdges, System.Collections.Generic.List`1[T] ok, System.Collections.Generic.List`1[T] error, System.Boolean inEdgesUsedToBeValid) (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/Graph.cs:387) UnityEditor.Graphs.Graph.WakeUpEdges (System.Boolean clearSlotEdges) (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/Graph.cs:286) UnityEditor.Graphs.Graph.WakeUp (System.Boolean force) (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/Graph.cs:272) UnityEditor.Graphs.Graph.WakeUp () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/Graph.cs:250) UnityEditor.Graphs.Graph.OnEnable () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/Graph.cs:245)
Answer by julianjulianov · Feb 27, 2021 at 09:40 AM
Hello! I also came across this problem and it was actually a serious problem. In the game menu I have the option to remove all sound effects via "Toggle". I have set a script for each new level to create one cloned enemy in more. In another script I store the data whether the sound effects in the game are on or off. I noticed that the cloned enemies still have a sound when "Toggle" is off, and I solved my problem like this:
using UnityEngine.UI;
using UnityEngine;
public class SoundEffectSaver: MonoBehavior
{
public Toggle toggleAudioChecker;
public Enemy [] _enemies;
public Crate [] _crates;
public void Start ()
{
toggleAudioChecker.isOn = PlayerPrefs.GetInt ("SaveBoolAudio")! = 0;
}
public void Update ()
{
_enemies = FindObjectsOfType <Enemy> ();
_crates = FindObjectsOfType <Crate> ();
PlayerPrefs.SetInt ("SaveBoolAudio", toggleAudioChecker.isOn? 1: 0);
int value;
value = toggleAudioChecker.isOn? 1: 0;
if (value == 1)
{
toggleAudioChecker.isOn = true;
GameObject.Find ("FlyFairy"). GetComponent <AudioSource> () .enabled = true;
foreach (Enemy enemy in _enemies)
{
enemy.GetComponent <AudioSource> () .enabled = true;
}
foreach (Crate crate in _crates)
{
crate.GetComponent <AudioSource> () .enabled = true;
}
}
else
{
toggleAudioChecker.isOn = false;
GameObject.Find ("FlyFairy"). GetComponent <AudioSource> () .enabled = false;
foreach (Enemy enemy in _enemies)
{
enemy.GetComponent <AudioSource> () .enabled = false;
}
foreach (Crate crate in _crates)
{
crate.GetComponent <AudioSource> () .enabled = false;
}
}
}
}
The original version was this:
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SoundEffectSaver: MonoBehavior
{
public Toggle toggleAudioChecker;
public void Start ()
{
toggleAudioChecker.isOn = PlayerPrefs.GetInt ("SaveBoolAudio")! = 0;
}
public void Update ()
{
PlayerPrefs.SetInt ("SaveBoolAudio", toggleAudioChecker.isOn? 1: 0);
int value;
value = toggleAudioChecker.isOn? 1: 0;
if (value == 1)
{
toggleAudioChecker.isOn = true;
GameObject.Find ("FlyFairy"). GetComponent <AudioSource> () .enabled = true;
if (SceneManager.GetActiveScene (). buildIndex> = 0 && GameObject.Find ("Monster") == true)
{
GameObject.Find ("Monster"). GetComponent <AudioSource> () .enabled = true;
}
if (SceneManager.GetActiveScene (). buildIndex> = 1 && GameObject.Find ("Monster (1)") == true)
{
GameObject.Find ("Monster (1)"). GetComponent <AudioSource> () .enabled = true;
}
if (SceneManager.GetActiveScene (). buildIndex> = 2 && GameObject.Find ("Monster (2)") == true)
{
GameObject.Find ("Monster (2)"). GetComponent <AudioSource> () .enabled = true;
}
if (SceneManager.GetActiveScene (). buildIndex> = 3 && GameObject.Find ("Monster (3)") == true)
{
GameObject.Find ("Monster (3)"). GetComponent <AudioSource> () .enabled = true;
}
if (SceneManager.GetActiveScene (). buildIndex> = 4 && GameObject.Find ("Monster (4)") == true)
{
GameObject.Find ("Monster (4)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (8)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (9)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (10)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (11)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (12)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (13)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (14)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (15)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (16)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (17)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (18)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (19)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (20)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find ("Crate (21)"). GetComponent <AudioSource> () .enabled = true;
GameObject.Find("Crate (22)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (23)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (24)").GetComponent<AudioSource>().enabled = true;
}
if (SceneManager.GetActiveScene().buildIndex >= 5 && GameObject.Find("Monster (5)") == true)
{
GameObject.Find("Monster (5)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (8)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (9)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (10)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (11)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (12)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (13)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (14)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (15)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (16)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (17)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (18)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (19)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (20)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (21)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (22)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (23)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (24)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (25)").GetComponent<AudioSource>().enabled = true;
}
GameObject.Find("Crate").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (1)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (2)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (3)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (4)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (5)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (6)").GetComponent<AudioSource>().enabled = true;
GameObject.Find("Crate (7)").GetComponent<AudioSource>().enabled = true;
}
else
{
toggleAudioChecker.isOn = false;
}
}
}
You came across "this" problem? How is your problem related to a null reference exception in Unity's internal editor Graph and Edge class? This doesn't seem to answer the question at all. You know this is a Q&A site, not a forum? The forum is over here, however I'm not sure your post would actually help anyone as your original code is horrible program$$anonymous$$g style and depends on countless hardcoded object names which is most likely the root cause of all your problems you may have had.
Hello! I am convinced that it will help many beginners like me. They should not put up with any problem, but look for a way to solve it. I succeeded and this annoying message no longer appears.
Answer by Kaldrin · Nov 11, 2020 at 07:56 PM
This seems to be an error inside of unity's assets You can't do anything about it but it shouldn't prevent the game from running fine.