playMaker

Author Topic: ArrayMaker Find all game objects by tag?  (Read 4462 times)

NvdS

  • Playmaker Newbie
  • *
  • Posts: 18
ArrayMaker Find all game objects by tag?
« on: June 01, 2015, 04:46:18 AM »
Hi Everyone

I'm very (very) new to ArrayMaker but for what I want I need it so I must learn it. At least a little. I'm trying to swap a material of several GameObjects with a specific tag. Since there is not so much support on ArrayMaker on youtube I'd like to try it here.

What I did so far is:

- add a Playmaker Array List proxy (Script) to my model with a reference (Mat_Swap) in it
- create an FSM with an Array List Add action and an Array List Find Game Object By Tag action on the first state. I entered the Mat_Swap Reference in both actions. Via a keydown action I move to the second state where I would like to swap the material by the Set Material action...

Now when I hit play I (thanks to live update) can see that all of the objects with the specified tag are listed in the array (even when I turn the Array List Add action off, so I'm not sure If I need this action too?). Right now I can't figure out how to swap the material of the objects on the list. I probably need to store the result of the Array List in some sort of Variable which I call in the Set Material? But as mentioned I didn't manage to fix it so any help would be really appreciated!


NvdS

  • Playmaker Newbie
  • *
  • Posts: 18
Re: ArrayMaker Find all game objects by tag?
« Reply #1 on: June 01, 2015, 08:10:19 AM »
I got a little further. I've managed to create an array and swap the material of the objects inside of it. But something weird happens. When I add another state with an Get Key Down action it error's. When I remove it, it works...

This is how I put it together so far:

Start state: Array List Find Objects By Tag + Array List Add (Game object: use owner + reference)

2nd State: Array List Get Next (Game object: use owner + reference + loop event (go to 3rd state) + finished event (go to 4th state)

3rd State: Set Material + Send Event (to loop to the 2nd State till all objects have been swapped)

4th State: no actions yet, but it's some sort of finished state I don't know yet what to do with it, but I use it to see if the FSM finishes the loop...

With these 4 states it works. But when I create new start State with a Get Key Down action it errors. It does swap all the materials, but it won't trigger the 'finished event' in the state with the Array List Get Next action. I get this error:

the fsmVar value <UnityEngine.Gameobject> doesn't match the value <System.Single>

Well this is some real abracadabra to me. It would be really nice if someone could help me out.

Thanks in advance!



« Last Edit: June 01, 2015, 08:16:08 AM by NvdS »

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: ArrayMaker Find all game objects by tag?
« Reply #2 on: June 01, 2015, 09:56:25 AM »
Hey Nico, I saw your comment on youtube and will reply here if that's okay.

I recreated your FSM but I took out a couple of states because I wasn't sure why they were necessary, if they are please let me know.

First state Array list find game objects by tag - this sets them all in your array for you so you do not need Array List add as well.

Second state Array list get next - I set the Loop event to go to the third state and the finished event to go to my last finished state like you have.

Third state is just Set Material - I have a finished transition that automatically sends it back to the second state.

Fourth state is blank.

After I tried it out it worked. I then set up a new first state and used Get Key Down and set it to backspace with a finished send event and that also worked without any errors. Maybe setting it like this may help. Let me know!
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

NvdS

  • Playmaker Newbie
  • *
  • Posts: 18
Re: ArrayMaker Find all game objects by tag?
« Reply #3 on: June 01, 2015, 10:15:03 AM »
Hi Sebastian,

Thanks for replying! I've tried both youtube and the forum, good to know you check both!

Your solution works! Thanks a lot! I also figured out what went wrong (although I don't understand why).

In the state where you create the array list you use a finished event (now I really understand the use of this event :)). I activated the playmaker events in the playmaker array list proxy and set the 'add' event to go to the 2nd state. This (obviously) didn't work...I guess I misunderstood the purpose of the playmaker events in the proxy...

Anyway...You helped me a lot! Thanks again. I'm gonna add some complexity now and might get back to you...

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: ArrayMaker Find all game objects by tag?
« Reply #4 on: June 01, 2015, 10:18:48 AM »
Great news, glad to see you have identified the problem and got it working.

The add event may work best for singular cases instead of group additions but its all based on the logic. nice work
« Last Edit: June 01, 2015, 10:20:41 AM by sebaslive »
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