How to activate/deactivate ticking outside the constructor ?

Hey guys ,

I 'm currently trying to active/deactivate tick outside the constructor , the fact is i don’t need it while there is no overlap event , and i don’t need it after the overlap’s end , I tried this :



OnBeginOverlap()
{
	this->SetActorTickEnabled(true);
}

OnEndOverlap()
{
	this->SetActorTickEnabled(false);
	
}

But as far as i saw it doesn’t works , this method should be called in the constructor , i tried different methods but i still don’t get it .

Do you have any idea ?

Thanks in advance and have a wonderful day !

You have it the other way around. You must use SetActorTickEnabled when toggling ticks outside of the constructor. Whereas in the constructor, you can just set values on PrimaryActorTick directly and the necessary registration will be done during actor construction.

Look at the code for SetActorTickEnabled and you’ll notice it expects PrimaryActorTick.bCanEverTick to be true. This might be the value you were referring to that has to be set in the constructor. It is false for Actors by default, so if you’ve subclassed an actor without setting bCanEverTick to true, it won’t ever be able to be registered for ticking. Put this in your actor constructor:



PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = false;


This will allow you to enable ticking later during your overlap, while starting with it disabled.

Ha yes i didn’t see it , i was thinking i should use one or another but not both

Thank you :slight_smile: