Timer + Changes by Tick which is more efficent

Hello everyone…

I have an event that needs to trigger every 1 second or so…

Accuracy is not a huge priority(it can be ± 30%). So I am wondering which of the following method is more efficient.

Using a timer that calls the function each second.
Or having a variable in the tick which checks if game time passed >1 second and call the function then update the existing variable at what game time the updating takes place.

If you only need Tick for this one feature, then it is guaranteed more efficient to

  1. Turn actor tick off

    a. Constructor



PrimaryActorTick.bCanEverTick = false;


b. During runtime


SetActorTickEnabled(false)


  1. Start your looping timer in Begin Play

:slight_smile:


If you are already using tick for stuff, then just checking the time yourself is what I would do.

:)

Rama

Thanks for replying Rama…

So a FTimer is not that efficient compared to manually checking per Tick(provided I use the tick for something else too).

I think the Timer does something similar under the hood. Because say it put the the time period to be something like 0.03 and I check the gap in game time in which the event is triggered, the gap is not 100% accurate but it maintains an average of 0.03.

I seem to recall Timers not working in UDK for non-ticking actors, but since in UE4 timers are handled by a timer manager this becomes a possibility. uhmmm interesting

envenger: yep they do the same, and the timer will not hit at exactly 0.03 seconds (because the CPU will never reach it after exactly 0.030000 seconds)
still using timers seems more efficient in the long run, because if your actors don’t tick they won’t be processed by the tick list which in the end can make a bit of a difference in scenes with large amounts of actors

Well, I am have an issue that timers work well in Editor, but when you make a build they don’t…had to rewrite to manual time cheking…

You should probably check out this thread: C++ Timer, Call Function every seconds - C++ - Epic Developer Community Forums

It has some discussion about the pros and cons of using UE4 timers vs ticking your objects and manually tracking times.