- Home /
Clear 1 field of Transform array
Hi there
I hope this is a small question. I have a multidimensional array that I declared as followed:
var things : Transform[,] = new Transform[10,20];
The array gets partially filled by Transforms. In the script I check, if a certain position is of the array is filled like this:
if(things[5,8]){
//Do stuff
}
This works like a charm so far. But now I need to make the same position "empty" again. For a "normal" array I found this:[http://docs.unity3d.com/Documentation/ScriptReference/Array.RemoveAt.html][1] [1]: http://docs.unity3d.com/Documentation/ScriptReference/Array.RemoveAt.html
Is there a way to do the same with my array? Kinda like:
things[5,8].delete
When I destroy the gameObject of the Transform, the array is still filled.
Thanks for your help mitti2000
Answer by Bunny83 · Apr 25, 2013 at 01:38 PM
A built-in array can't be resized. RemoveAt will remove an element. That's not possible with "real" arrays ( the JS Array class is not a real array ;)). If you just want to "clear" an element, set it to null:
things[5,8] = null;
Transform is a class and therefore a reference type. You just set the reference to null.
Btw: When you destroy the object the reference will also become null, but it's delayed one frame.
Your answer
Follow this Question
Related Questions
Accessing boolean properties from array of transforms 1 Answer
Remove an object from an array and destroy it (C#) 2 Answers
Array of transforms 1 Answer
transform.rotation problem 1 Answer
how do you delete variables or arrays? 3 Answers