Enabling Tick from the AActor : how?

Hi,

I created a small class inherited from the AActor class. Unfortunately I’m unable to enable the tick functions. I have tried many parameters/boolean but I guess I’m missing one. Here is what I have already tested :

AEXILInteract::AEXILInteract(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

	bWantsBeginPlay = true;
	
}

void AEXILInteract::PostBeginPlay()
{
	Super::PostBeginPlay();
	
	SetActorTickEnabled(true);
	RegisterAllActorTickFunctions(true, true);
	
	if( IsActorTickEnabled() )
		elog("Tick is enabled");
		
	PrimaryActorTick.bCanEverTick = true;
		
	if( CanEverTick() )
		elog("Can Ever TICK §§");
}

The function “elog” is just a shortcut to call the Log functions. Both write in the log perfectly, meaning the boolean are enabled. Still, the Tick and ActorTick stay mute (each has a elog call too).

I would have expected that SetActorTickEnabled(true); would be enough to enable the Tick function, but it seems it’s not the case. What variable should I enable to get the function to work ?

In the constructor you just want to do:

PrimaryActorTick.bCanEverTick = true;

Thanks, it’s working. Why changing this in the PostBeginPlay doesn’t work ? Does this mean you can’t change it to enable/disable the tick function after the creation in the scene on an actor ?

Think of it in the same way that unrealscript works: you cannot set bStatic anywhere except in defaultproperties because it is constant. So by extension, you can’t set bStatic in PostBeginPlay either.

I think from this thread you might be able to find a way to enable / disable Tick.

Thanks for the explanation. However neither PrimaryActorTick or bCanEverTick is defined as a const in the current header (Actor.h and EngineBaseTypes.h).

You’re right, but I’m putting your question it into perspective. That was the point. If you look at the comment right above the variable, it says this:

/** If false, this tick function will never be registered and will never tick. Only settable in defaults. */
UPROPERTY() uint32 bCanEverTick:1;

So based on this, the engine reads in this variable before gameplay even starts, not while the game is actually running (postbeginplay). I imagine the reason they set it to const in unrealscript in the first place was b/c the devs didn’t want users scratching their heads over why Tick was not being called (ironically, the situation that’s happening right now :p)…

I see ! Thanks again ! :wink: