Custom GameMode And GameState Won't Tick [resolved]

Hello everyone,

I realize this issue has come up in the past but so far I haven’t found a solution to this and have met a dead end.

In my recent project I created c++ classes for GameStateBase and GameModeBase respectively. Then I noticed that neither BeginPlay or TIck are ever fired. So I went troubleshooting:

  1. Both Classes are seleceted in the project settings.
  2. The constructor fires like expected.
  3. Ticking is enabled for both. Super::Tick() is included. Code compiles fine.
  4. PrimaryActorTick.bStartWithTickEnabled and PrimaryActorTick.bCanEverTick are set to true.
  5. Neither GameMode or GameModeBase (or both GameStates for that matter) function in this regard.
  6. I tested the same with derived Blueprint classes. Doesn’t work either.

Here’s there relevant code of the c++ classes (parented to the blueprints used most recently in the settings.)

GameState.h:

UCLASS()
class CITYBUILDING_API ACPP_GameState : public AGameState
{
	GENERATED_BODY()
	
public:
	ACPP_GameState();

	virtual void Tick(float DeltaTime) override;
	virtual void BeginPlay() override;
};

GameState.cpp:

#include "CPP_GameState.h"

#include <Runtime/Engine/Classes/Engine/Engine.h>

ACPP_GameState::ACPP_GameState() {
	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bStartWithTickEnabled = true;
	PrimaryActorTick.bCanEverTick = true;
	if (GEngine) {
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FString::Printf(TEXT("GameState created")));
	}
	UE_LOG(LogTemp, Warning, TEXT("GameState created in CPP"));
}

void ACPP_GameState::BeginPlay() {
	Super::BeginPlay();
	UE_LOG(LogTemp, Warning, TEXT("GameState BeginPlay in CPP"));
}

void ACPP_GameState::Tick(float DeltaTime) {
	Super::Tick(DeltaTime);

	if (GEngine) {
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FString::Printf(TEXT("GameState ticking")));
	}
	SetClockwork(DeltaTime);
	UpdateTimeDate();
	UE_LOG(LogTemp, Warning, TEXT("GameState ticking in CPP"));
}

GameMode.h:

UCLASS()
class CITYBUILDING_API ACPP_GameMode : public AGameMode
{
	GENERATED_BODY()
	
public:
	ACPP_GameMode();
	virtual void BeginPlay() override;
	virtual void Tick(float DeltaTime) override;
};

GameMode.cpp:

ACPP_GameMode::ACPP_GameMode() {
	PrimaryActorTick.bCanEverTick = true;
	PrimaryActorTick.bStartWithTickEnabled = true;
	UE_LOG(LogTemp, Warning, TEXT("GameMode created in CPP"));
}

void ACPP_GameMode::BeginPlay() {
	Super::BeginPlay();
	UE_LOG(LogTemp, Warning, TEXT("GameMode BeginPlay in CPP"));
}

void ACPP_GameMode::Tick(float DeltaTime) {
	Super::Tick(DeltaTime);
	UE_LOG(LogTemp, Warning, TEXT("GameMode ticking in CPP"));
}

I haven’t tried to replicate this on an empty project yet, because this project doesn’t have any content other than starter content, player pawn movement and camera setup. I created it a few days ago on a fresh Engine Installation (4.23).

Ok, so I have NO idea what changed. I restarted the project this morning and still had the same issue. I then did the following (basically just messing around):

  1. I changed the game mode from my custom BP (which inherits from my custom c++ class, which in turn inherits from AGameMode) to TopDownGameMode BP which was provided on project creation.
  2. Suddenly BeginPlay and Tick events both start firing in my GameState.
  3. I changed the project settings back to my C++ GameMode and my custom GameMode Blueprint and behold: It’s still working.
  4. Saved and restarted the project and it’s still working.

The ONLY thing I did was switching to the TopDownGameMode and back to my custom GameMode and suddenly everything works fine. No changes in the Blueprint, my code or various settings other than messing around in the Maps & Modes section. Beats me why though.

Hello,
In my case I had a GameMode class inheriting from AGameMode and a GameState class inheriting from AGameState. The problem I had was that the Tick function was not being triggered on my GameState instance. After some digging around, I found this line in AInfo’s constructor :
PrimaryActorTick.bCanEverTick = false;
(AInfo is a parent class of AGameState).

Adding PrimaryActorTick.bCanEverTick = true; in my GameState’s constructor fixed the issue for me.
Cheers.

3 Likes