Detach a Single, Random Child Object?

Hi,

I'm working in iOS. I've got a parent object that has 30 child objects(enemies). The child objects all share the same 1 mesh, but there are 30 separate skeletons(rigs). I'm using this setup rather than instantiate and destroy enemies because I want all the enemies to be 1 drawcall for performance reasons.

As it stands, I can get them all on screen animating and moving around with 1 drawcall. When an enemy is hit, rather than destroy the GO it is moved to an empty GO off screen where it waits to be reused. When it's time to reuse the enemy I want a single enemy(child) to be detached from the parent GO.

Detach.Children doesn't work because I only want to detach one-not all of them.

Any ideas?

Thanks in advance.

Well, if you don't care what order the enemies are pulled off of the holder GO, then you can run a GameObject.FindGameObjectsWithTag("Enemy") and then use a for loop to iterate through them until you find a gameobject that has (transform.IsChildOf(holderObject.transform) == true). You could then reparent your enemy to the screen GO.

I think this will work on a first-in, first-out basis (based on which object gets reparented to your empty holder object first. If they are all the same type of enemy (or you don't care), this might work. If you have different types of enemies and you don't want them recalled in the same order they were killed, you'll have to create a new array of the enemies that have (transform.IsChildOf(holderObject.transform) == true), and then randomly iterate through them to pick one.

That's how I would do it (which isn't saying much /grin/)...