Tick not being called on a APaperFlipbookActor

I have made a new APaperFlipbookActor class. I then give it a flipbook in code, the flipbook has a frame rate of 0, as I want to manually move and control it to generate an effect.

The editor make a file without a constructor even. Just GENERATE_BODY()

So I add a Constructor, and a Tick override. These are overridden, there is no warning or error.

Tick never gets called. I google, read up and find you need to enable it with PrimaryActorTick.bCanEverTick = true; in the constructor. Still doesn’t work, I throw in PrimaryActorTick.bStartWithTickEnabled = true; it still doesn’t work.
After searching, looking at the PrimaryActorTick class and hunting I slow add more and more off this to the BeginPlay ( which does get called)

if (!PrimaryActorTick.IsTickFunctionRegistered())
	{
		PrimaryActorTick.bCanEverTick = true;
		PrimaryActorTick.bStartWithTickEnabled = true;
		GEngine->AddOnScreenDebugMessage(-1, 20, FColor::Red, "NOT Registered");
		PrimaryActorTick.TickInterval = 1.0f / 60.0f;
		PrimaryActorTick.Target = this;
		PrimaryActorTick.RegisterTickFunction(GetLevel());
	}
	if (!PrimaryActorTick.IsTickFunctionRegistered())
	{
		GEngine->AddOnScreenDebugMessage(-1, 20, FColor::Red, "NOT Registered STILL");
	}

“NOT registered” is displayed when I run, but “NOT Registered STILL” does not. So the register completes. But still I don’t have a tick. If I set the FPS on the Flipbook to be something other than 0, say 5, it updates and animates as expected so there has to be a tick somewhere.

What else do I have to do?
Why do I have to do this in the first place?

Can you please show how are you overriding the tick function?

h

UCLASS()
class MIM_API AAMayhemSmoke : public APaperFlipbookActor
{
	GENERATED_BODY()
public:
	AAMayhemSmoke();
	virtual void Tick(float DeltaTime) override;
	virtual void BeginPlay() override;

protected:
	float NextFrameTimer;
	int CurrentIndex;

	UPaperFlipbook* SmokeFB;
	
};

cpp

void AAMayhemSmoke::Tick(float DeltaTime)
{
	GEngine->AddOnScreenDebugMessage(-1, 20, FColor::Red, "FRAME");
	Super::Tick(DeltaTime);

	NextFrameTimer -= DeltaTime;
	if (NextFrameTimer < 0.0f)
	{
		int Frame = sFrameIndex[CurrentIndex];
		if (Frame > 0)
		{
			GetRenderComponent()->SetVisibility(true, true);
			GetRenderComponent()->SetPlaybackPositionInFrames(Frame, false);
		}
		else
		{
			GetRenderComponent()->SetVisibility(false, true);
		}
		CurrentIndex++;
		if (CurrentIndex > kMaxFrameIndex)
		{
			CurrentIndex = 0;
		}
		NextFrameTimer = 1.0f / 60.f;
	}
}

If I remove all the tick set up code and just have the normal
PrimaryActorTick.bCanEverTick = true; in the constructor and convert the object to an AActor then Tick gets called as expected. So this is an APaperFlipbookActor specific issue.

To those that come after…
I found the docs for it, PAPER2APaperFlipbookActor | Unreal Engine Documentation for some reason its a PAPER2A version while the class name is not and just APaperFlipbookActor.
To which unlike APaperCharacter the constructor ( which is not in the .h file ) is
APaperFlipbookActor(const FObjectInitializer& ObjectInitializer); and as such while calling a normal () constructor will get you a flipbook object that works and plays. However you won’t be able to get the tick working. You need to add the const FObjectInitializer& ObjectInitializer to your constructor and call the super with it, for example

AYourActor::AYourActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	PrimaryActorTick.bCanEverTick = true;
}

and the Tick will now fire as expected.

1 Like