ToonTanks UI Widgets Not Working (Lecture 154)

I’ve gone through the lectures on creating widget blueprints for Game Start and Game End…twice each. I’ve followed carefully, ensuring each event graph matches exactly as shown. I’ve made it about 2/3 through the changes to add the widgets to the GameMode Blueprint where the widgets are tested and find the Game Start blueprint doesn’t remove the widget once the countdown timer ends. I get the folliwing in the output log:


This appears when the timer runs out.

Consequently, when I destroy the turret, the Game End widget does not appear.

To make sure the VS code for GameModeBase isn’t the issue, I’ve copied the github commits for the .h and .cpp files to eliminate any chance of hand coding errors.

Ant thoughts on this? It doesn’t keep the game from running, but also doesn’t make the experience complete since the game end widget never appears.

Here is the code for TankGameModeBase.h

// Fill out your copyright notice in the Description page of Project Settings.

#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()

protected:
	virtual void BeginPlay() override;

public:
	void ActorDied(AActor* DeadActor);
	UFUNCTION(BlueprintImplementableEvent)
	void GameStart();
	UFUNCTION(BlueprintImplementableEvent)
	void GameOver(bool PlayerWon);

private:
	int32 TargetTurrets = 0;
	int32 GetTargetTurretCount();

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Player", meta = (AllowPrivateAccess = "true"))
	APawnTank* PlayerTank;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Game Loop", meta = (AllowPrivateAccess = "true"))
	int StartDelay = 3;


	void HandleGameStart();
	void HandleGameOver(bool PlayerWon);

};

and here’s the code for TankGameModeBase.cpp:

// Fill out your copyright notice in the Description page of Project Settings.

#include "TankGameModeBase.h"
#include "ToonTanks/Pawns/PawnTank.h"
#include "ToonTanks/Pawns/PawnTurret.h"
#include "Kismet/GameplayStatics.h"

void ATankGameModeBase::BeginPlay()
{
    TargetTurrets = GetTargetTurretCount();
    PlayerTank = Cast<APawnTank>(UGameplayStatics::GetPlayerPawn(this, 0));

    HandleGameStart();

    Super::BeginPlay();
}

int32 ATankGameModeBase::GetTargetTurretCount()
{
    TSubclassOf<APawnTurret> ClassToFind;
    ClassToFind = APawnTurret::StaticClass();
    TArray<AActor*> TurretActors;
    UGameplayStatics::GetAllActorsOfClass(GetWorld(), ClassToFind, TurretActors);
    return TurretActors.Num();
}


void ATankGameModeBase::ActorDied(AActor* DeadActor)
{

    if (DeadActor == PlayerTank)
    {
        PlayerTank->PawnDestroyed();
        HandleGameOver(false);
    }
    else if (APawnTurret* DestroyedTurret = Cast<APawnTurret>(DeadActor))
    {

        DestroyedTurret->PawnDestroyed();

        TargetTurrets--;

        if (TargetTurrets == 0)
        {
            HandleGameOver(true);
        }
    }

}

void ATankGameModeBase::HandleGameStart()
{
    GameStart();
}

void ATankGameModeBase::HandleGameOver(bool PlayerWon)
{
    GameOver(PlayerWon);
}

In your widget blueprints look at your Set Timer by Function Name nodes and look at their times. It sounds like one of them has a time of 0 or less.
e.g.
image

Thanks. That was it. Not long after I submitted the quesion, I found the error in calling the Remove UI function with Set Timer by Function in the GameStaert blueprint.

I still had to rebuild the GameOver blueprint to make it work, but all is well now.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.