Array Data For Each Child

I’d like to save array data that I can use later for each child. For example, if I had a variable

position : Array;

How would I add a new set data for each child that I can use later? I have like 50 objects so I’d rather not make variables for each one. I would use:

for (var child : Transform in transform)
{
       //here
}

But where //here is, I want to add a new set of data if not already set, and if it’s set, I want to save the position under that set of data. Thanks in advance.

You can either create a GameController which each object reports to, or create a reference in the GameController that creates the object with the reference to.

In the first, you would simply send a message to the GameController that says something like GC.SendMessage(“ReportingForDuty”, gameObject); This would send a message out to the GameController that stores the gameObject into an array for later use.

The second method has the GameController create the object and at the same time stores that object into an array.

On both examples, you could also send a message to the GameController to remove the object from the array.

Lastly, I will point out that an ArrayList probably would handle the objects better than an Array simply because Remove(Object) is a feature where it is not in a normal Array in JS. Also, getting an object is faster as well.

Thanks! It’s a little confusing at first but I get the concept.

ArrayList is basically the same as Array. They both have RemoveAt, and they both should be avoided because they’re slow and not typesafe. Instead, use built-in arrays such as GameObject[ ] for arrays of fixed size, or use generic Lists such as List. for arrays which grow/shrink.

–Eric