playMaker

Author Topic: Firing Events : Best Practices  (Read 4484 times)

Murcho

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 54
Firing Events : Best Practices
« on: April 21, 2011, 10:26:57 PM »
I want to get an idea of the best way to be firing events, not only from within an FSM, but also between FSMs.

In the "Making an Animation Graph" tutorial video, the FSM uses no transitions between states, and uses Global Transitions to move between the states.  However in the "Using Trigger to Open Doors" tutorial video, the door's FSM is setup with local transitions, and uses them to transition between states.

My initial understand of how to use Global Events was to fire events from external sources, from another FSM or from a script, but they can obviously be fired locally as well.  Also with the local transitions, they can be triggered by events fired externally as show in the opening doors tutorial.  So what I thought was the way to do things is probably wrong right now.

So I guess my question is, when is it right to use Global Transitions over Local Transitions, and is there any best practices advice available, or should this become a Community Wiki page?


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Firing Events : Best Practices
« Reply #1 on: April 22, 2011, 03:07:47 AM »
I used global transitions in the Animation Graph partly out of habit from using Havok Behavior. The animation graphs we built in HB often had top level states with global transitions (wildcards in HB) so the character would remain responsive in any state. In animation graph you'll generally have a mix of local and global transitions. For example, an animation graph might have local transitions to build nice sequences of animations, but a global transition to a Ragdoll Death State that can be instantly entered from any state.

It's a trade-off really - global transitions are convenient, but you lose some ability to react specifically based on the current state - you just jump to the new state. It's functionally equivalent to adding a local transition from every state to the new state - it's convenient, but you can't now decide that one state needs a different reaction to that event (although that would be a nice feature!).

I don't know if there are any hard and fast rules. As long as you understand how they work they just give you more flexibility in how you work. I think over time it would be nice to collect some examples on the Community Wiki...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Firing Events : Best Practices
« Reply #2 on: April 22, 2011, 04:17:45 AM »
Hi,

 I'd say from the current experience I am gaining, that I use global state in two cases.

1: when the even is triggered from outside, say another fsm wants to inform another about something. If you divide your behavior in several fsm, global event allows you concurrent behaviors, because one single fsm can only have one active state ( as Alex mentionned as well). So global events mixed with splitted fsm is really powerful stuff.

2: When my fsm gets too complicated and within it I want to shortcuts and avoid hardwiring. Say a fsm is a sequence of logical steps, and at some point you would like to reuse or jump to another state in that process, instead of hardwiring, I simply create a global event and call that. The fsm look less like a spider's web...


Also, I think it's very dangerous to use too much global transitions without a tight framework or very well managed project, because loose coupling will give you headaches down the road if it gets out of control. Who sent what to who?, you'll get weird behaviors not knowing why ( just because you forgot that little fsm in the corner firing the wrong event at the wrong time. You gain fantastic freedom, but this isn't it ideal without a proper framework during debugging to really show you clearly events activities.

Bye,

 Jean

Bye,

 Jean