If I have an array of gameobjects (used to quickly iterate through those specific objects to enable/disable them, index positions don't matter), and I destroy one of the gameobjects through some means other than `Array.RemoveAt`, will the array automatically shorten itself, or will it leave a hole in the array by having the array index where that gameobject was refer to null?
As a side question, would `Array.RemoveAt` actually destroy the gameobject referred to at that index, or would it just remove the reference to it from the array?
The array and the object are completely separate. Destroying the gameobject will leave a null value in the array. RemoveAt will remove it from the array, but not from the game. You'll have to do both manually.
I test it ’ game object has removed but array length and its content has no change .
that means object in hierarchy and scene removed but in array has it.
bellow the test script :
#pragma strict
var arr : Array ;
var box : GameObject ;
function Start () {
arr = new Array();
for(var ii=0 ; ii<10 ; ii++){
arr.Add(GameObject.Find((“box”+ii)));
}
Debug.Log("0 : "+arr.length);
for(ii=0 ; ii