Does "Missing" mean the same thing as "None&q

I’m trying to troubleshoot some code, and apparently I keep referencing an object that has been destroyed. I’ve got my existence checks in place, but just to make sure: does “Missing” mean the same thing as “None” when it comes to the reference itself? Or do I have to set it to none?

Missing means at somepoint the object existed, and a reference to it was assigned but now the object got destroyed.

When hit hit play you want to pause the game, and check if the reference is still there, to see if it happens because some script destroys the referenced game object, or because the reference has not been assigned.

If you click on the error in the console once, it shows you a reference to the object where the missing reference exception comes from.

hi!

i also got a missing reference exception, but there is no useful stacktrace and i don’t know how to find the cause of the problem.

MissingReferenceException: The object of type ‘GameObject’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.SendMouseEvents+MouseOverPair.SendMessage (System.String name)
UnityEngine.SendMouseEvents.DoSendMouseEvents ()

Where i can find the reference? Or how is it marked? I can’t find it, every object in the scene is a ‘GameObject’.
I found a hint, that destroyed gameObject can be tested against null. I changed my only access function, but all game objects i’am accessing are not null. but it didn’t help.

Here some code-fragements, how i access the destroyable items in my project:

original access on destroyable items:

// find all items in scene
public Item[ ] GetItems(){
return Item.FindObjectsOfType(typeof(Item)) as Item[ ];
}

added null check when accessing destroyable items:

// find all items in scene
public Item[ ] GetItems(){
Item[ ] items = Item.FindObjectsOfType(typeof(Item)) as Item[ ];
ArrayList activeItems = new ArrayList();

foreach(Item item in items){

// avoid not-referenced game objects
if (item.gameObject != null) {
activeItems.Add(item);
}
}

int index = 0;
Item[ ] result = new Item[activeItems.Count];
foreach(Item item in activeItems){
result[index] = item;
index++;
}
return result;
}

destruction:

// destroy all references before creating new ones
foreach(Item item in GetItems()) {
DestroyImmediate(item.gameObject, false);
}

the way i reference all destroyable items:

// destroy old
foreach(Item item in GetItems()) {
item.doAnything();
}

I hope, anyone can help. thx!

i found a workaround to get the stacktrace back on MissingReferenceExceptions.

in my case i had two GameObjects with attached c# scripts, Board and Item.
from the Item-script I called Board.OnItemClick(this) to handle clicks of all items on one central place.
there I made a mistake, one method indirectly destroyed the item and later I destroy it again.

but i didn’t see any stacktrace, it looked like the problem that happens inside of unity before my code was invoked.
bad situation, stop working. add a forum task and going home :frowning:
before i arrived my flat, i got the idea to avoid direct execution of mouse handling.
i just put the item object on Board.OnItemClick(item) into a queue and handle it on Board.Update().
it works and i got the stacktrace back.

but the problem remains, when calling a method of another script and a MissingReferenceException occurs, you got no really helpful stacktrace. my luck was, i just had one mouse handler …