Gamemode not firing Tick

Hey guys, I’m completely new at Unreal and just got out of Unity, and thought I’d give a try at scripting in this while following along Unreals Battery Game Tutorial found here https://docs.unrealengine.com/latest/INT/Videos/PLZlv_N0_O1gYup-gvJtMsgJqnEB_dGiM4/mSRov77hNR4/index.html

Everything more or less went smoothly until EP 13 where we incorporate the Tick function in the GameMode script, as my tick evidently isn’t seemingly running at all.

Here is the C++ Code ABatteryCollectorGameMode.cpp

#include "BatteryCollector.h"
#include "BatteryCollectorGameMode.h"
#include "BatteryCollectorCharacter.h"
#include "Kismet/GameplayStatics.h"

ABatteryCollectorGameMode::ABatteryCollectorGameMode()
{
	//base Decay Rate
	DecayRate = 0.01f;
}

void ABatteryCollectorGameMode::Tick(float DeltaTime)
{

	Super::Tick( DeltaTime );

	UE_LOG(LogClass, Log, TEXT("Battery Drain"));

}

And here is the head ABatteryCollectorGameMode.h

#pragma once
#include "GameFramework/GameModeBase.h"
#include "BatteryCollectorGameMode.generated.h"

UCLASS(minimalapi)
class ABatteryCollectorGameMode : public AGameModeBase
{
	GENERATED_BODY()

public:
	ABatteryCollectorGameMode();

	virtual void Tick( float DeltaTime ) override;

protected:
	//rate that power is reduced
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Power")
	float DecayRate;
};

I trimmed out the largely irrelevant parts. I’m pretty new to C++ and UE4 in general, so if there is some glaring issues in the code or if there’s an issue with UE4 that I’m not aware of, I’d appreciate some feed back.

Thanks

Hi,

In your ctor try adding this first

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

If this not helps reparent to AGameMode, that Base can bee too much streamlined. And just advice - don’t mix game mode/game state base variants with normal one.

1 Like

That did it, thank you very much!

I had exactly the same problem after following the video tutorial. Thanks!

Found below comment from the official API document:

Note that Tick is disabled by default,
and you will need to check
PrimaryActorTick.bCanEverTick is set to true to enable it.