playMaker

Author Topic: Remember and set child materials  (Read 1880 times)

Gibbagobba

  • Playmaker Newbie
  • *
  • Posts: 3
Remember and set child materials
« on: April 01, 2018, 04:05:27 AM »
I'm creating an FSM that can be applied to any prefab which sets its material to a colored wireframe based on its tag while storing the original material in a variable. When the wireframe button is pressed again, it sets the material back using this variable.

The main problem I'm facing however, is in applying this to nested objects. For example, I parent all my level geometry to an empty object for organization. This also means I can just apply my FSM to this empty object instead of every individual child. I can also set all of them to the wireframe material using this custom action: http://hutonggames.com/playmakerforum/index.php?topic=6429.msg31357#msg31357

Unfortunately, this also means I can't store every object's material in a single variable and the FSM no longer knows what material(s) to restore and to which objects (making them all pink). How would I go about solving this problem?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Remember and set child materials
« Reply #1 on: April 01, 2018, 10:13:41 AM »
Hi.
You might want to look into arrays.
Have 1 array for the objects and 1 array for the materials to "restore" to.
Then loop thru each index from the arrays

Gibbagobba

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Remember and set child materials
« Reply #2 on: April 01, 2018, 11:15:08 PM »
I used the Ecosystem action "Get All Recursive Children" to store the child objects in an array. Since one does not already exist that I can tell, I attempted to duplicate and modify the action to recursively get the materials of these children and store them in a second array. The FSM gets stuck on this action so I'm not sure what I should be doing.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Remember and set child materials
« Reply #3 on: April 02, 2018, 04:11:06 AM »
Hi. After getting them into an array, you can loop thru the array using 'array get next', get the material and place in another array on the same index.

Gibbagobba

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Remember and set child materials
« Reply #4 on: April 02, 2018, 10:11:09 PM »
What command can store each child's material into an array index? None of them accept arrays as variables.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Remember and set child materials
« Reply #5 on: April 03, 2018, 01:58:13 AM »
Hi.
Here is how you can do this :