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:
- Both Classes are seleceted in the project settings.
- The constructor fires like expected.
- Ticking is enabled for both. Super::Tick() is included. Code compiles fine.
- PrimaryActorTick.bStartWithTickEnabled and PrimaryActorTick.bCanEverTick are set to true.
- Neither GameMode or GameModeBase (or both GameStates for that matter) function in this regard.
- 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).