Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: purbanics on March 24, 2014, 06:03:22 AM

Title: Get Next Child question
Post by: purbanics on March 24, 2014, 06:03:22 AM
Hi,

I am using the Get Next Child action and it does go through all the children but not in the order I would like. Which would be the order I see them in the Hierarchy.
I have renamed all the children with an increasing number at the end of their names so they would be Get in order from 1 to last, but for some reason (probably the sequence of adding them to the parent) they iterate through in different order.

Please explain why this is and where is the information that causes this unorderly? iteration sequence.

Thanks,
Peter
Title: Re: Get Next Child question
Post by: purbanics on March 24, 2014, 06:09:34 AM
 :) Fixed.

I still don't know where Unity stores the order of children (it's not based on their name) but I could solve my problem by simply unparenting all items then parenting them back.
After that the Get Next Child goes through them in the order of their incremental names.

Title: Re: Get Next Child question
Post by: jeanfabre on March 27, 2014, 06:02:43 AM
Hi,

 Child ordering is UNRELIABLE in Unity. you should account for that in your loop and make use of a different mean to make sure your logic doesn't fail if you get your iteration in another order.

bye,

 Jean
Title: Re: Get Next Child question
Post by: purbanics on March 27, 2014, 06:28:55 AM
Thanks for the info.

Right now it iterates through them the way I would like (in their named order) but you say that's unreliable and could be messed up anytime.
So in that case to make sure it always works exactly in the desired order I will need to do some string manipulation to build the child names incrementally in the loop and get each child based on their name.

Thanks,
Peter
Title: Re: Get Next Child question
Post by: jeanfabre on March 27, 2014, 07:39:35 AM
Hi,

 I would actually take the problem the otherway around: why do you need to iterate in order in the first place?

 Bye,

 Jean
Title: Re: Get Next Child question
Post by: Lane on March 27, 2014, 07:46:46 AM
The only time I've actually use Get Next Child is if there is only one child and the name is not consistent or is unknown. :)

Why don't you use arrays for this?
Title: Re: Get Next Child question
Post by: purbanics on March 27, 2014, 09:09:34 AM
(I use Get Random Child when there is only one.)

I have not used arrays before.
Do you mean using arrays with this ArrayMaker add-on?  :
https://hutonggames.fogbugz.com/default.asp?W715

Thanks,
Peter
Title: Re: Get Next Child question
Post by: sebaslive on March 27, 2014, 11:06:13 AM
Thats the one! Welcome to the world of Arrays. It took me a while to 'get' it and I feel like I still don't but the samples help and tutorials are coming but for now what you need for now is to use an array list. It seems like it would handle your needs better than a hashtable.

There are actions for the arraylist that say get next in the index so it will go in order. Pop all the little children into the array and that will be a better form of get next child using that action. The index will keep them in the order you put them!
Title: Re: Get Next Child question
Post by: purbanics on March 28, 2014, 02:17:20 AM
Thanks, Sebastian for the info.
I'll try that out then.

Br,
Peter