playMaker

Author Topic: Get Next Child question  (Read 3655 times)

purbanics

  • Junior Playmaker
  • **
  • Posts: 55
Get Next Child question
« 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

purbanics

  • Junior Playmaker
  • **
  • Posts: 55
Re: Get Next Child question
« Reply #1 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.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Next Child question
« Reply #2 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

purbanics

  • Junior Playmaker
  • **
  • Posts: 55
Re: Get Next Child question
« Reply #3 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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Next Child question
« Reply #4 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

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Get Next Child question
« Reply #5 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?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

purbanics

  • Junior Playmaker
  • **
  • Posts: 55
Re: Get Next Child question
« Reply #6 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

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: Get Next Child question
« Reply #7 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!
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

purbanics

  • Junior Playmaker
  • **
  • Posts: 55
Re: Get Next Child question
« Reply #8 on: March 28, 2014, 02:17:20 AM »
Thanks, Sebastian for the info.
I'll try that out then.

Br,
Peter