Jump to content
Sign in to follow this  
Igor Q.

Event Listener. Game Update vs. Timer

Recommended Posts

One of the tips suggested in Ylands loading screen is to use Event Listeners instead of delay timers when possible.

 

If I'm using a script which tracks a players movement. (it could be anything but this is the simplest example)

Is it more efficient to use the "On Game Update" Event Listener instead of delay timer? (what about looping instructions that have +10 commands?)

Share this post


Link to post
Share on other sites

I use the event listener almost always and everywhere. especially during animations. when it comes to a single player game, it can handle 50+ commands. Another advantage is in the interval, because the event listener works in the interval 0.025 and the timer works in the smallest interval 0.03. it's not a big difference, but it's obvious in animations.

Share this post


Link to post
Share on other sites

Hi, it depends:

Time trigger + script delay with small time delay may result with more than 1 triggering per 1 frame. (one long frame on slow PC)

Event listener + On Game Update event will trigger only once per each frame.

 

So:

A) you are fine to track movement once per second -> I would use Time trigger

B) you want to track movement once each frame -> I would use Event listener + "On game update"

Share this post


Link to post
Share on other sites

@Houp btw, what is the difference between "on fix update" and "on update" event in event listener?

Share this post


Link to post
Share on other sites

If i remember right, the Fix Update Event will keep running when game start, and can't stop. Sometimes it's not good.

By the way, we can use Time delay command in the function callback, to simulate Time trigger.

Share this post


Link to post
Share on other sites
On 6/4/2022 at 5:46 AM, Mello1223 said:

@Houp btw, what is the difference between "on fix update" and "on update" event in event listener?

"On update" triggers once per frame -> you have 80 FPS then it triggers 80x in one second. You have 30 FPS then it triggers 30 times per second.

"On fixed update" does not depend on your FPS. It will trigger the same amount of times per second each second. It may trigger even 2 or more times per one frame.

"Fixed update" is used for physics/movement of objects with collisions.

Those events are not Ylands specific. You can for example check: https://learn.unity.com/tutorial/update-and-fixedupdate#

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×