Hi all,
After finishing the EndGameWidget lecture, my game is acting weird - the camera position is changed, gameplay functionalities are gone (can’t move, shoot, etc.). Game practically gets stuck as soon as starting message is shown. My TankGameMode.h and .cpp code is as below. I would appreciate any pointers since I cannot seem to understand what’s causing the issue.
Header file:
#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:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Game Loop")
int32 StartDelay = 3;
virtual void BeginPlay() override;
UFUNCTION(BlueprintImplementableEvent)
void GameStart();
UFUNCTION(BlueprintImplementableEvent)
void GameOver(bool PlayerWon);
};
Implementation:
#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();
}