Page 1 of 1

Warum bekommt es immer noch NullReferencexception, nachdem er alles in Einheit überprüft hat?

Posted: 17 Feb 2025, 08:58
by Anonymous
Der Code sieht so aus: < /p>
Dictionary handlerDict= new Dictionary(); // handlerDict was initialized in the beginning and poped up with values properly early on.

void Update()
{
if (obj1!= null && handlerDict.ContainsKey(obj1.tag))
{
print($"obj1.name = {obj1.name}, obj1.tag = {obj1.tag}");
print($"handlerDict[obj1.tag] = {handlerDict[obj1.tag]}, obj2= {obj2}");
handlerDict[obj1.tag].Invoke(obj2); // I got NullReferenceException here
}
}
< /code>
In der Konsole habe ich unzählige Drucke, da es im Update () -Methodenaufruf ist. Und alles im Muster wie folgt: < /p>

OBJ1.Name = GameObjectname_xxx (Klon), obj1.tag = GameObjectname_xxx < /p>
HandlerDict [obj1.tag] = System.Action`1 [unityEngine.gameObject], obj2 =
GameObjectname_yyy (Klon) (UnityEngine.gameObject) < /p>
nullReferencexception: Objektreferenz nicht Setzen Sie auf eine Instanz eines
Objektklassennamea+ C.B__274_9 (unityEngine.gameObject x)
(bei Assets/_scripts/xxx/xxx.cs: 4407)
< /Blockquote>
Ich denke /Code> Anruf, oder habe ich hier etwas vermisst? < /p>
Jede Hilfe wird geschätzt! Danke!