I have an array of GameObjects that I need to iterate through, but occasionally the GameObjects will have been destroyed, and unfortunately it’s very complicated for me to remove them from the array at the time when they are destroyed.
I’ve been trying to use the following code to just get around the error, but it doesn’t work on the iPhone - only in the editor.
Is there another way that I can effectively say “If the object hasn’t been destroyed, then do the following”?
try
{
if (Contents)
{
for(var i : GameObject in Contents)
{
var thisItem : consumable_object_control = i.GetComponent(consumable_object_control);
thisItem.canBeTouched = true;
}
}
} catch(err) {}
Just for information, it probably doesn’t work on the iPhone because you build with ‘fast but no exceptions’. If you want to use exceptions, build with ‘slow and safe’. Obviously that will have a performance impact, but that might not be an issue depending on the nature of your game (this is something you should measure on the device).