playMaker

Author Topic: Get Next Child  (Read 10453 times)

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Get Next Child
« on: January 31, 2012, 07:14:22 PM »
Currently to loop through all the children of a GameObject you have to use Get Child Count, Get Child Num, Int Add, and Int Compare  - which is a bit of a pain!

Get Next Child does this all in one action.

See the attached screenshot for usage. You can replace the Debug action with any action you want to perform on all children of the GameObject.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Next Child
« Reply #1 on: February 01, 2012, 12:39:45 AM »
Hi,

 Interesting, could you explain the process, I  don't really understand how that works.

-- Will it not hit the infinite loop warning this way? I do that too, but to prevent the infinite loop, I set th eevent with 0.00001 delay.

-- does that mean that when a transition is pointing to its own state, the action is not reinstanciated and therefore all variables values are still there, and onEnter is called again.

 That's excellent! Ill experiment with this.

Bye,

 Jean

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: Get Next Child
« Reply #2 on: February 01, 2012, 02:55:41 PM »
Yes i looked at this and it has possibilities..

Could the Set Color with children that Jean did the other day be done with this type of code?

Q

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Next Child
« Reply #3 on: February 01, 2012, 05:05:45 PM »
Hi,

 yes it would actually, tho saving the original color would be then difficult without a custom action anyway.

 Bye,

 Jean

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: Get Next Child
« Reply #4 on: February 04, 2012, 10:59:31 AM »
Right.. i see what you mean by saving the original color..

I 3/4 built the change color with children Action but then lost my direction on it and decided i did not have time to figure out the last bit of it.. But my approach was to save the original in an array before changing them. I assume you did the same sort of thing. I have not looked at your script yet.

You are seriously the script master Jean.. I wish i had your skills. And you are very generous.. Thank you!

Q

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Next Child
« Reply #5 on: February 09, 2012, 01:30:55 AM »
Hi,

 I am definitely far from being a master... but I guess one of my strengths is to never give up... This is two different things! I need to learn c# properly, there are still a lot of feature and key aspect that I do not fully understand when I write c#.

What I do is maintaining a Look up hash table for each material that I will change color, I store the material reference as the key and the color as the value. So if two GameObjects use the saem material within the hierarchy, I simply store it once. When reverting to original colors, I simply scan this look up table and apply the original colors back

 It might have some flows, but it works for me so far.

 Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Next Child
« Reply #6 on: February 09, 2012, 04:40:33 AM »
Hi,

 Regards the implementation, I would actually suggest that we test to detect when next child is not available to be:

Code: [Select]
if (nextChildIndex >= go.transform.childCount)
Because if during the process of iteration, an action remove a child or several, then nextChildIndex would be higher than  go.transform.childCount, and would result in a runtime error. So really we only want to proceed if nextChildIndex is within the range, not simply equal to the count.

 Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Next Child
« Reply #7 on: February 13, 2012, 02:51:52 AM »
Hi,

 There is another flow with the current set up of this action. It doesn't work if the state is called a second time.

currently as set up, if we have 1 child;

1: we go for the first time in the "getNextChild" state
-- GetNext child action iterate to the next
-- sendEvent loop
2: we go for the second time in the "getNextChild" state
-- GetnextChild detects end of loop, and trigger "NoMoreChildren"

NOW. if I trigger again the "getNextChild" state
 -- within GetNextChild: noMoreChildren is equal to true, so the "finishedEvent" event is not called, because the function will never be reached again.

The current way I solve this is to check again for "no more child" at the end of the function DoGetNextChild. Then I can Re-iterate trough the childs if I want to by simply coming back to this state somehow.

Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Next Child
« Reply #8 on: February 13, 2012, 03:15:11 AM »
Hi,
 

 Here is a modified version implementing my suggestions above: http://hutonggames.com/playmakerforum/index.php?topic=1088.0


Bye,

 Jean
« Last Edit: February 13, 2012, 03:19:35 AM by jeanfabre »