To clarify, I am following the ToonTanks section of the course. The Countdown is intended to begin as soon as the game starts. The text GO! pops up after a set amount of time then is removed.
Now to be honest, I’m finding Unreal pretty tough to get my head around so for now, I’m just following along. I’ve checked time and time again and I followed the lectures to the letter to set this up, so I have no clue why this isn’t working.
In terms of implementation, the widgets are being called through this blueprint:
This has the following C++ classes associated with it:
TankGameModeBase.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "TankGameModeBase.generated.h"
class APawnTurret;
class APawnTank;
UCLASS()
class TOONTANKS_API ATankGameModeBase : public AGameModeBase
{
GENERATED_BODY()
private:
APawnTank* PlayerTank;
int32 TargetTurrets = 0;
int32 GetTargetTurretCount();
void HandleGameStart();
void HandleGameOver(bool PlayerWon);
public:
void ActorDied(AActor* DeadActor);
protected:
virtual void BeginPlay() override;
UFUNCTION(BlueprintImplementableEvent)
void GameStart();
UFUNCTION(BlueprintImplementableEvent)
void GameOver(bool PlayerWon);
};
TankGameModeBase.cpp
#include "TankGameModeBase.h"
#include "ToonTanks/Pawns/PawnTank.h"
#include "ToonTanks/Pawns/PawnTurret.h"
#include "Kismet/GameplayStatics.h"
void ATankGameModeBase::BeginPlay()
{
Super::BeginPlay();
HandleGameStart();
}
void ATankGameModeBase::ActorDied(AActor* DeadActor)
{
if(DeadActor == PlayerTank)
{
PlayerTank->HandleDestruction();
HandleGameOver(false);
}
else if (APawnTurret* DestroyedTurret = Cast<APawnTurret>(DeadActor))
{
DestroyedTurret->HandleDestruction();
if(--TargetTurrets == 0)
{
HandleGameOver(true);
}
}
}
void ATankGameModeBase::HandleGameStart()
{
TargetTurrets = GetTargetTurretCount();
PlayerTank = Cast<APawnTank>(UGameplayStatics::GetPlayerPawn(this, 0));
GameStart();
}
void ATankGameModeBase::HandleGameOver(bool PlayerWon)
{
GameOver(PlayerWon);
}
int32 ATankGameModeBase::GetTargetTurretCount()
{
TArray<AActor*> TurretActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), APawnTurret::StaticClass(), TurretActors);
return TurretActors.Num();
}