Does 'trigger once' affect performance?

  • Is it good practice to use 'trigger once' when possible and does it have any effects on performance?

    I would imagine any boolean check or instance variable check that doesnt change often would benefit? For example:

    Player.isWalking > Set animationspeed to 5.

    If Im not using Trigger once i would image that the system will try to set animation speed every tick while true. So would a trigger once condition in these kind of places have a postive and noticable effect on performance?

  • That's correct.

    Using Trigger once would reduce unnecessary processing repeatedly and improve FPS slightly, especially when the action is a heavy one (like a Physics velocity to zero, Set position to a fixed point of a large sized sprite, or Effects parameter, etc.)

    Whereas, setting Global variables every tick would not really have any noticeable difference.

    Though, it is always best to use Trigger Once, or using "On" conditions where ever possible! and have least possible actions at "Every tick" (and all other constantly true conditions).

  • Another trick is combining trigger once with "wait for signal" to create your own custom "once-off" conditional triggers. Simply add 'trigger once' with no other conditions, then make the first action "wait for signal". The event will only run once.

    Use case: Explicit structuring of startup logic, irrespective of the order of events. So, if you are configuring objects in a way that is order dependent, structure into separate 'trigger once' events that signal thru each other. Then you could, say, locate 'startup' logic for different actors in their own groups which could be arranged as you please.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Answer your own performance questions with measurements

    Without making any measurements, I would guess it makes no difference either way, since the (tiny and irrelevant) amount of work checking the "trigger once" condition is probably about the same as the (tiny and irrelevant) amount of work in the "set animation speed" action. Of course if you make measurements you can prove this for yourself.

  • I made some tests on my game, and it turns out trigger once actually make a difference in many cases. I identified a couple of places where trigger once would make sense. And checking debug, those areas(groups) in the code went from using 0,8%-1.2%cpu to 0,1%-0.2% cpu. Let's say i have 20 places in my code where i can get this kind of benefit it all adds up to some serious processing power saving, which is really noticeable on mobile.

    Biggest difference was noticed on places where i used "For each"...

  • On a second note I also noticed that limiting the amount of true's at any given point is beneficial. Optimising the code to have as few true's as possible using more conditions like 'every X seconds', comparing distances, and other checks. etc etc.... Every time something is false, nothing is done, and the system moves on to next event.

    A good example is when I was Z ordering every object in a family (40+ objects on screen)... I managed to optimize this code from using 10%+ CPU to less than 1% just by limiting the amount of true, and still get the same result.

  • Yeah, it depends on the action really.

    For me, I had Set text (for many different text objects) in Every tick and constantly-true conditions, which was taking up all the memory. I removed most of them to change when they need to change (only once) and I could see a huge improvement in FPS.

    This is also mentioned here: along with many other useful and specific performance tips.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)