I’ve been following the Battery Collector tutorial series on YouTube to learn how to use Unreal Engine, which has already demanded learning on the fly how to solve various issues that came up because it isn’t up to date with the current version of the engine (Mainly adding #import stuff that was apparently not needed back then)
In part 14, we override the gamemode tick to update various aspects of the player’s character, using the code below :
BatteryCollectorGameMode.h :
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#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 at which the character loses power
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Power")
float DecayRate;
};
BatteryCollectorGameMode.cpp :
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "BatteryCollectorGameMode.h"
#include "BatteryCollectorCharacter.h"
#include "UObject/ConstructorHelpers.h"
#include "Kismet/GameplayStatics.h"
ABatteryCollectorGameMode::ABatteryCollectorGameMode()
{
// set default pawn class to our Blueprinted character
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/ThirdPersonCPP/Blueprints/ThirdPersonCharacter"));
if (PlayerPawnBPClass.Class != NULL)
{
DefaultPawnClass = PlayerPawnBPClass.Class;
}
// Base Decay Rate
DecayRate = 0.01f;
}
void ABatteryCollectorGameMode::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// Check that the character is a BatteryCollector Character
ABatteryCollectorCharacter* MyCharacter = Cast<ABatteryCollectorCharacter>(UGameplayStatics::GetPlayerPawn(this, 0));
if (MyCharacter)
{
// if the character's power is positive
if (MyCharacter->GetCurrentPower() > 0)
{
// Decrease the character's power using the decay rate
MyCharacter->UpdatePower(-DeltaTime * DecayRate*(MyCharacter->GetInitialPower()));
}
}
}
The problem is : this override of the Tick function seems to NEVER get executed. More Specifically, the UpdatePower function call contained in the cpp file never happens, even when I removed both if statements. The power is properly updated when the function is called elsewhere, which leads me to believe this Tick() function actually doesn’t tick ??
I have no idea what is happening (or, more precisely, why it isn’t happening) and my research through the documentation has yielded no actionable results. I hope I have provided enough information, please help me