Custom GameState class does not tick

I have a GameState class which inherits from AGameStateBase. The BeginPlay() method fires correctly, but no breakpoints or functionality are hit in the Tick() function.

#include "CustomGameState.h"

void ACustomGameState::BeginPlay()
{
	testInt += 1;
}

void ACustomGameState::Tick(float DeltaTime)
{
	testInt += 1;
}

The test integer starts at 0 and goes to 1, but never gets higher than that.

I’m setting the GameState in the GameMode’s constructor like so:
GameStateClass = ACustomGameState::StaticClass();

The inheritance ladder looks like this:
ACustomGameState : AGameStateBase : AInfo : AActor

The Tick function I’m overriding actually comes from AActor. Is there something extra I need to do either in the editor or in C++ to get that actor to start ticking?

Hi friend!

Good question. Can you check that the field bCanEverTick is set to True?

Also did some digging and this thread may contain some good info as well! Custom GameMode And GameState Won't Tick [resolved] - #3 by Elou44

Hey NightmareGames!

It looks like your BeginPlay function is missing a call to Super::BeginPlay()
Like

void ACustomGameState::BeginPlay()
{
	Super::BeginPlay();
	testInt += 1;
}

Does it tick correctly if you add that in?

1 Like

Thanks for the pointers. I can’t tell if bCanEverTick was true, but I’ve set it to true now. I’ve also added Super::BeginPlay, but there’s no change to the integer count.

Here’s my current game state:

void ACustomGameState::BeginPlay()
{
	Super::BeginPlay();

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

	testInt += 1;
}

void ACustomGameState::Tick(float DeltaTime)
{
	testInt += 1;
}

Not sure if it matters but put these in constructor instead

PrimaryActorTick.bStartWithTickEnabled = true;
PrimaryActorTick.bCanEverTick = true;
1 Like

Okay. This is my new game state class. Still not ticking, unfortunately.

ACustomGameState::ACustomGameState()
{
	PrimaryActorTick.bStartWithTickEnabled = true;
	PrimaryActorTick.bCanEverTick = true;

	testInt += 1;
}

void ACustomGameState::BeginPlay()
{
	Super::BeginPlay();

	testInt += 1;
}

void ACustomGameState::Tick(float DeltaTime)
{
	testInt += 1;
}

I took another look at my game mode (which I’m not using for anything yet) and noticed it’s still only the constructor.

As a wild hunch, I added a BeginPlay method to see what would happen.

void ACustomGameMode::BeginPlay()
{
}

Even though it contains no code, adding that caused the game state to start ticking. I don’t have a good explanation for that, aside from a vague knowledge that those two classes are closely related.

Even weirder is that after removing ACustomGameMode::BeginPlay(), the GameState still ticks. I especially can’t explain that one.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.