Download

Dynamically enable / disable Tick?

Is it possible to either unregister or register the Tick function dynamically. I have some code that I only ever want to be run if the object is owned by a Local Player (not necessarily always a client either), and I want to avoid calling ‘IsLocallyControlled’ every tick to work that out. It’d be much more efficient for me to be able to only register the tick function on the players game.

However, from the looks of it you can only declare the actor tick group in the Constructor, and it’s not safe to call some functionality there (to determine if it’s a local player or not). Any other way I can do this? Otherwise I have a whole bunch of actors ticking who don’t need to be, and not doing anything most of the time too.

why dont you just call this->SetActorTicksEnabled(true/false); ?

in the ctor i set bCanEverTick = true;

and during runtime i call those funcs when i want to enable or disable tick events

Hello, i use the function SetActorTickEnabled(bool) to disable or enable actor ticking during runtime. Maybe set your actor to tick inside the constructor and inside BeginPlay() if isLocallyControlled = false use SetActorTickEnabled(false). Just an idea, im not sure if it works.

Yeah just found that function, forgot it even existed. Will use that instead! Nice one guys :slight_smile: