playMaker

Author Topic: iOS Prefabs, Screenpick and Create - Odd results[SOLVED]  (Read 4266 times)

Ffz

  • Playmaker Newbie
  • *
  • Posts: 5
iOS Prefabs, Screenpick and Create - Odd results[SOLVED]
« on: June 24, 2013, 08:27:17 AM »
I start out by creating a number of prefab clones via a standard script in an array, I then have a FSM that is located on the prefab that waits for a touch event. On touch, screenpick, we check our global variable touch counter, if 1 then save the game object into another global variable and kick off a create game object function (particle effect). If 2, save hit item as current item (vector 3 position), then create a particle effect both on the old position and the new position and clear the counter global variable.

If I debug the flow from 1 I see that 9 objects are created, not one? Not sure why, thought it might be related to the array of prefabs but on changing the number of prefabs created the same (9) objects are created.

Please help, I'm a noob.

--- Update ---

I recreated a new prefab, attached the FSM to it and changed from a touch based initialise to a mouse-up. It looks like I have a logic problem here, I do a mouse-pick and a bool-set to true if it succeeds. I save the game object that it hits. I then do a bool-test and if true kick off the create particle effect section. The effect of this is that the particle effect is then kicked off n times (number of items in array) which tells me that I need to not use a bool-test on prefabs because they will all, always be set to the same. So, my logic tells me to use the mouse-pick-event and then try and save the game-object info... what's the best way to do this? get FSM game object, drop to global variable?

--- Update 2 ---

Got it working with the following: First mouse pick, then mouse pick event and drive successful event through to another state that creates the object. No global/local variables.

Problem I have now is to convert this scenario to a touchscreen one with prefabs, there is no screen pick event function that would allow me to duplicate this logic? How else could I accomplish this?
« Last Edit: June 27, 2013, 07:12:02 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: iOS Prefabs, Screenpick and Create - Odd results
« Reply #1 on: June 25, 2013, 02:06:06 AM »
Hi,

 For this, you need to separate the logic of catching user input and the behavior it self. Create three Fsm:

-- A Fsm to catch mouse inputs
-- A Fsm to catch touch input
-- A Fsm to perform the desired behavior

Implement a global event like "SCREEN PICK" and this is your entry point to perform the behavior, the touch and mouse fsm simply fire that global event.

Does that make sense? You can pass values to events using "set event data" action, pass the screen position for example. then you have a very clean system that can scale very well. You can have more ways of triggering your behavior, and more fsm can react to that screen pick, for example to give visual feedback or to fire more behaviors

Does that make sense?

bye,

 Jean

Ffz

  • Playmaker Newbie
  • *
  • Posts: 5
Re: iOS Prefabs, Screenpick and Create - Odd results
« Reply #2 on: June 25, 2013, 06:48:45 AM »
Are the FSM's then not tied to the physical prefabs, they are independent?

Do I end off the touch event/mouse up with a send message containing the position and then start off the third FSM with a screen pick global... sorry, trying to get the hang of these FSM's  ;)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: iOS Prefabs, Screenpick and Create - Odd results
« Reply #3 on: June 26, 2013, 05:29:52 AM »
Hi,

 Yes, Fsm are tied to their respective GameObject, they are unity components.

 You can run fsm templates, but that's already advanced. You define a fsm as a template and in the fsm component, you point to the template resource and it will run that one.

yesm touch event and mouse event respective fsm will fire a global event "SCREEN PICK" and pass in that event the position using the action "set event data", then your screen pick fsm will indeed have a global transition set to "SCREEN PICK" and that's where it should start its behavior, fiurst getting the position using action "get event info" and then process it.

bye,

 Jean

Ffz

  • Playmaker Newbie
  • *
  • Posts: 5
Re: iOS Prefabs, Screenpick and Create - Odd results
« Reply #4 on: June 27, 2013, 06:58:50 AM »
Perfect, working like a charm!! 8)