Does 'trigger once' affect performance?

Get help using Construct 2

Post » Tue Jun 16, 2015 5:37 pm

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?
Follow my progress on Twitter
or in this thread Archer Devlog
B
40
S
17
G
17
Posts: 977
Reputation: 12,626

Post » Tue Jun 16, 2015 6:12 pm

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).
Last edited by Hasan999 on Tue Jun 16, 2015 6:53 pm, edited 2 times in total.
B
10
S
2
Posts: 109
Reputation: 982

Post » Tue Jun 16, 2015 6:29 pm

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.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Wed Jun 17, 2015 9:47 am

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.
Scirra Founder
B
397
S
236
G
88
Posts: 24,389
Reputation: 194,448

Post » Thu Jun 18, 2015 8:55 am

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"...
Follow my progress on Twitter
or in this thread Archer Devlog
B
40
S
17
G
17
Posts: 977
Reputation: 12,626

Post » Thu Jun 18, 2015 9:37 am

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.
Follow my progress on Twitter
or in this thread Archer Devlog
B
40
S
17
G
17
Posts: 977
Reputation: 12,626

Post » Thu Jun 18, 2015 12:31 pm

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: https://www.scirra.com/manual/134/performance-tips along with many other useful and specific performance tips.
B
10
S
2
Posts: 109
Reputation: 982


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, Uk4dee, Yahoo [Bot] and 23 guests