locked
Is the order ("sequence") of Behaviors significant?

    Question

  • I notice that when you're setting Behaviors on an Actor, each Behavior has an Up/Down error with the tooltip "Move Behavior earlier/later in the sequence."  Is this just to help me organize them, or does the order affect functionality?

    More broadly, I'm curious about how to make one behavior dependent/conditional on another: can you group behaviors so that if one event fires, multiple behaviors take place in response, or is it appropriate just to set them all up to watch for the same event?

    Monday, September 29, 2008 12:56 AM

Answers

  • The order of behaviors with the exception of collision events and a few others impacts when a behavior will fire during a given frame if its event also fired that frame.  In most cases the order doesn't matter, but it occasionally does when say a filter on one behavior depends on the execution of another behavior as in jumping.  There's a complete explanation of event ordering here:

     

    http://www.popflywiki.com/EventModel.ashx

     

    As for making multiple behaviors fire from the same event, you have a couple options.  The easiest and simplest is to just to create them all and set them to fire off the same event.  If you don't have an overly compicated set of behaviors this is what I would recommend.  Another option is to change all the behaviors to code,  and copy/paste the custom code from each behavior into a single behavior and delete the rest.  This has the potential to have unintended consequences or performance issues (particularly if and when the game creator moves to a C# based Silverlight 2 implementation, non-code behaviors should be significantly faster than code behaviors), but should work.  Finally, you can use event ordering to do something similar to what the jump shortcut does - have a trigger behavior set a property and have the rest of your behaviors filter on that property using an every-frame timer event or a property change event and have a second behavior set that property back to 0 at the end of the frame after your behaviors fire.

     

    Anyway, that's the long answer.  The short answer is at this point in time it's generally simplest to just set the event individually on each behavior, but you can find ways to be tricky and set up dependencies using properties or custom code. 

     

    Tuesday, September 30, 2008 5:45 PM

All replies

  • The order of behaviors with the exception of collision events and a few others impacts when a behavior will fire during a given frame if its event also fired that frame.  In most cases the order doesn't matter, but it occasionally does when say a filter on one behavior depends on the execution of another behavior as in jumping.  There's a complete explanation of event ordering here:

     

    http://www.popflywiki.com/EventModel.ashx

     

    As for making multiple behaviors fire from the same event, you have a couple options.  The easiest and simplest is to just to create them all and set them to fire off the same event.  If you don't have an overly compicated set of behaviors this is what I would recommend.  Another option is to change all the behaviors to code,  and copy/paste the custom code from each behavior into a single behavior and delete the rest.  This has the potential to have unintended consequences or performance issues (particularly if and when the game creator moves to a C# based Silverlight 2 implementation, non-code behaviors should be significantly faster than code behaviors), but should work.  Finally, you can use event ordering to do something similar to what the jump shortcut does - have a trigger behavior set a property and have the rest of your behaviors filter on that property using an every-frame timer event or a property change event and have a second behavior set that property back to 0 at the end of the frame after your behaviors fire.

     

    Anyway, that's the long answer.  The short answer is at this point in time it's generally simplest to just set the event individually on each behavior, but you can find ways to be tricky and set up dependencies using properties or custom code. 

     

    Tuesday, September 30, 2008 5:45 PM
  • Thanks for the thorough response, Ben.  I really admire what you've done here.
    Tuesday, September 30, 2008 11:36 PM
  • No problem, thanks Mike!

     

    Thursday, October 09, 2008 8:25 PM