Remove a particular object from list on trigger exit

Trying to remove a specific object from my list on trigger exit is prooving difficult for some reason.
As you can see i’ve done everything i can to try to debug this using print and Debug.Break… i’ve narrowed it down to when comparing the GetInstanceID is failling. If removing objects from a list/array is it ok to iterate backwards through the list/array?

Some help would be greatly apreciated!

function OnTriggerExit(other : Collider) {
print(other.transform.GetInstanceID());

if(other.transform.tag == "Cube")
	{
		if(cubeList.Count != 0)
			{print("iterating through Cube List");
				for(var i : int = cubeList.Count-1; i >= 0; i--)
					{	
					print("in iteration loop");
					var currentCubeObject : GameObject = cubeList*;*
  •   				print("the current cube ID " + currentCubeObject.GetInstanceID());*
    
  •   					if(currentCubeObject.GetInstanceID() == other.transform.GetInstanceID())*
    
  •   						{	cubeList.RemoveAt(i);	Debug.Break();}*
    
  •   					if (i == cubeList.Count) {break;}*
    
  •   				}*
    
  •   			//cubeList.RemoveAt(cubeList.Count-1);*
    
  •   			//print("cube exited the colum " + transform.name);*
    
  •   			//print("break for cube removal from " + transform.name);*
    
  •   			//Debug.Break();*
    
  •   		}*
    
  •   }*
    

}

You could use list.Remove(other). I suppose GameObject overrides Equals to compare instance ids. If it's too long, try looking only for the occurence index inside the loop (break out once you found it ) and remove after, sort of like that :

var index : int = -1;
for( var curr : GameObject in cubeList ){
    ++index;
    if( curr.GetInstanceID() == other.transform.GetInstanceID() )
        break;
}
if( index >= 0 && index < cubeList.Count )// ocurrence was found
    cubeList.RemoveAt(index);