playMaker

Author Topic: Add Component to Children  (Read 2422 times)

stvbabb

  • Junior Playmaker
  • **
  • Posts: 66
Add Component to Children
« on: November 06, 2017, 11:02:37 AM »
Hello,

I'm trying to add a script to a bunch of child objects of one parent but, catch is that the child objects and generated procedurally at run time. I can't figure out how to get this working, though.

I have a setup state that waits one second for the objects to build at run time, then I've tried a couple of different things.

Set a tag for the children
Then, Find Game Objects With Tag, in this case 'roads'
And then... I'm lost. I want to then add a script to each of those objects with that tag of 'roads.'

Any ideas?

Cheers and thank you,
Steve

stoffl

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Add Component to Children
« Reply #1 on: November 06, 2017, 11:52:57 AM »
hi, there is a action on the ecosystem called get next child or get next child with reset option. You can loop through all childs, compare the tag, and add the component.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Add Component to Children
« Reply #2 on: November 06, 2017, 12:39:38 PM »
Hi,
How are the child objects 'generated'

If you are using 'create object' , you can store the object in a variable and then add to an array, then you could loop thru the array to add the component.

What component are you adding? maybe it is better to have the component already on it but disabled, so you only need to enable it.

stvbabb

  • Junior Playmaker
  • **
  • Posts: 66
Re: Add Component to Children
« Reply #3 on: November 07, 2017, 02:30:03 AM »
Hi djaydino,

The child objects are generated at run time using some real world map data from Mapbox https://www.mapbox.com/unity/. I don't have to do anything to fetch the map data, just set up some editor stuff and it's good to go.

There are no prefabs I can set up with the Nav Mesh component already attached. It would be a lot easier, of course, but data streamed in that I really have nothing to do with before run time is difficult.

I really like your idea of looping through an array, but I just can't seem to figure out arrays in Playmaker. I see the "Array Get Next" but after that action, I just can't figure out how to then add or even do something with those objects in the array.

I can dig around for some more of those tutorials, but I'm not connecting with it.

If you have any other suggestions, that would be awesome.

Cheers and thank you,
Steve


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Add Component to Children
« Reply #4 on: November 07, 2017, 11:17:11 AM »
Hi,
There are some array and array maker (more advanced version)
 tutorials on the user tutorial wiki page

to logic works like this:

State 1 (has the array get next action) : the array gets the next item in its list (on the 1st time it will get the item on the index number set into the "Start Index")
Store the Result into a variable.
And it will send the "Loop Event" transition. (in this case connected to State 2)

State 2 :
Do whatever you need to do with the variable (in your case, add a component)
Add a finished transition and point it back to state 1.

When it goes back to state 1 it will get the next item and go again to state 2.
and continues to loop until the last item or if the last item was on the index stated on the "End Index".
The array get next action will send the finished event.

Your loop is done then :)