WorldTimer Vs Tick

I know what is difference between two, so that not the issue.

It’s more about best practices. Where is it best to use WorldTimer or Tick ? What is the perfomance difference when you need lots of objects each doing something in different intervals.

I’ve been looking at UT code (and shooter for that matter), and I see that weapons are using Timers, while I perosonally used Tick, because it was just simpler to use.

But there might be something I don’t know ir it just matter of preference ?

Timers are more efficient in some cases. It’s generally not a good idea to have too many objects ticking every frame if they don’t need to be. Let’s look at a hypothetical example where we want to trigger some action to happen in two seconds using a tick function.



MyClass::Tick(float Delta)
{
    if (bActivated)
    {
        Timer -= Delta;
        if (Timer < 0.f)
        {
            DoStuff();
            bActivated = false;
        }
    }
}

MyClass::Trigger()
{
    bActivated = true;
    Timer = 2.f;
}


By itself this isn’t a big deal but let’s pretend we have 100 of these. Most of the time most of them aren’t going to be activated so they shouldn’t do anything. However, all of the inactive objects still need to Tick every frame and check if they should do something. If they used a timer they wouldn’t need to. If ten of them are currently activated we need to update the time remaining and check if they should run ten times. The timer manager groups things together so that most of the time we don’t need to check and update all of the timers.

Thanks for explanation!

One question though.
Would it be possible to make ticking more efficient by just setting flag if object should tick at all.

I have done it with my custom Ticker implementation in UObject (FTickableGameObject), and there is that one function IsTickable().

What I did, is when I didn’t not need object to tick (for example is not used currently), I just set this function to return false. And then when object needed to tick (for example input pressed), it returned true.

I guess the same thing is doable with actor by setting PrimaryActorTick.bCanEverTick to true or false, depending on user input and state of the game ?

Its actually more efficient to be Event driven altogether if you can pull it off or at least use events/delegates when possible over a Tick / Timer. This is assuming the the object on a timer/tick is waking up to check for the event.

There are ways to improve the efficiency of ticking but you shouldn’t worry about them until it becomes a problem. In general ticking doesn’t scale as well as an event driven system for large numbers of objects. There are some places where ticking is a better choice. If you need to update your objects every frame then you should use a tick. If your objects don’t need to update all the time you should consider using the timer manager instead.

If you’re using ticking for everything and it works for you that’s fine. Using just ticking has the advantage of simplicity. If you’re aware of the trade offs there is nothing saying you can’t make one decision now and change it later if other factors change. It sounds like ticking is working for you and you find it easier to use. If you find that your performance starts suffering because you’re spending too much time ticking you can look at moving some things to the timer manager then.