playMaker

Author Topic: Optimizing trigger events - is it run several times?  (Read 2823 times)

FritsLyn

  • Full Member
  • ***
  • Posts: 191
Optimizing trigger events - is it run several times?
« on: July 12, 2013, 02:15:39 PM »
Hi, I cannot at this stage see any delay, but I'd hate to make "dirty code".

My question is:

Is the example shown on the attached picture going to run several tests for trigger events, or just 1, and then do 4 comparisons?

I am probably going to have some 20 in total when done (this is the main character). Should I make one trigger event and then get info, put to string, make switch etc - or is it "clean" as shown?

Thanks :)
« Last Edit: July 12, 2013, 03:40:31 PM by FritsLyn »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Optimizing trigger events - is it run several times?
« Reply #1 on: July 12, 2013, 03:45:45 PM »
Hi,

 You are fine. what is bad practice ( imo...) is to really on TriggerStay, while it's fine in normal scripts, it's not really good in fsm, because events are fired every frame. instead prefer using trigger enter and exit and maintain a boolean flag.

but in your case it's all good, I do this all the time.

bye,

 Jean

FritsLyn

  • Full Member
  • ***
  • Posts: 191
Re: Optimizing trigger events - is it run several times?
« Reply #2 on: July 12, 2013, 03:50:51 PM »
Thanks a bunch! :)

tutukun

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Optimizing trigger events - is it run several times?
« Reply #3 on: July 12, 2013, 04:39:26 PM »
I create a custom action with pairs of tag and event to check for different tag value. Something like this:

Code: [Select]
[CompoundArray("tag Switches", "Compare Tag", "Send Event")]
[UIHint(UIHint.Tag)]
public FsmString[] collideTags;
public FsmEvent[] sendEvents;

Then inside DoTriggerEnter

Code: [Select]
if (trigger == TriggerType.OnTriggerEnter)
{           
   for (int i = 0; i < collideTags.Length; i++)
   {
      if (other.gameObject.tag == collideTags.Value)
      {
         Fsm.Event(sendEvents[i]);
         StoreCollisionInfo(other);
         return;
      }
   }   
}


Hope that help  :)
« Last Edit: July 12, 2013, 04:42:08 PM by tutukun »

FritsLyn

  • Full Member
  • ***
  • Posts: 191
Re: Optimizing trigger events - is it run several times?
« Reply #4 on: July 12, 2013, 04:43:57 PM »
Uh - I cannot code enough to make use - that's why i am using PlayMaker :)

I can read the code though, but am in doubt, would this be a cleaner (faster) method?

Thanks!

tutukun

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Optimizing trigger events - is it run several times?
« Reply #5 on: July 12, 2013, 04:49:57 PM »
Uh - I cannot code enough to make use - that's why i am using PlayMaker :)

I can read the code though, but am in doubt, would this be a cleaner (faster) method?

Thanks!

its definitely cleaner than having one trigger event for each tag value. Performance-wise, it should be more or less the same .

FritsLyn

  • Full Member
  • ***
  • Posts: 191
Re: Optimizing trigger events - is it run several times?
« Reply #6 on: July 12, 2013, 04:51:10 PM »
Thank you :)

(Clean in CPU cycles is all that matters to me ;) )