Tell if an object is missing?

I have created some code to remove objects from an array when then are missing due to destruction. However, it doesn’t work!

var temp = new Array()
for (a = 0; a<grens.length; a++)
{
if (grens[a])
{
temp.Add(grens[a])
}
}
grens = temp;

How might I tell if grens[a] is missing? Also, I’m not getting any error messages.

it can’t be missing, as long as there is a valid reference in, regular objects won’t be destructed at all.

Exception are naturally unity objects which you killed through DestroyImmediate

Otherwise your approach is right given you ever set it to null
Generally though you shouldn’t have null references as objects should remove themself from the list when they are requested “to be gone”

@Dreamora:

I see what you are saying, but the objects are being displayed in the editor as missing…

I will give more info, Incase it helps.
Grens is a script type array. The objects are not being destroyed by the script that holds this array, but rather the scrips in the array it’s self. When ever one of these objects destroys it’s self, it is not removed from the array, the array instead displays a missing - even with the current code.

Ah, I found a way…

var temp = new Array();
for (a = 0; a<grens.length; a++)
{
if (!grens[a].dead)
{
temp.Add(grens[a]);
}
}
grens = temp;

As the object has a delayed destruction, I can set a variable called “dead” in the array script, and have the array-holding script keep an eye for that variable.