Blueprint Runtime Error "Accessed None Trying to Read Property)

So I’m having some issues having now finalised the widgets.

  1. The error in the title

After exiting playmode, I’m getting this error, both if the tank is destroyed and if all turrets are destroyed by the tank.

  1. Text is not updating

The text still comes up as ‘TEXT BLOCK’ and is not updating accordingly. I’ll include screenshots of the widget event graphs further down.

  1. No timer at the start

The game just starts, so the Start Game Widget isn’t even being utilised.

Game Start Widget:

image

image

Game End Widget:

I think I’ve included everything in this post.

Been racking my brains on this for three days now and I can’t make heads or tails of it. Probably something minor that I’m missing :confused:

Hey!

So reading the error message:
“Accessed none trying to access” = means a nullpointer was found
“property TextGameResult” = this is the variable that was null
“Blueprint: WBP_GameEnd” = the name of the blueprint where the error is
“Function: Initialise Text” = The function where the null pointer is
“Node: SetText(Text)” = The node where the null pointer was caught

So within your GameEndWidget in the InitialiseText function you have a Set node for “Text Game Result” but you never “Select Asset” meaning you are passing a null value to the “SetText” node and thats where the null pointer is happening. Make sure you choose an appropriate value from the dropdown. Also I have a hunch you might run into the same error in GameStartWidget InitialiseText where you havent set a value for TextCountdown either.

Cheers!

Ok so that solved the error thanks!

But the countdown is still not working. The game should start with a countdown before it begins, but on play it still just starts immediately. I’ve done the same thing in the Start Game Widget that I did in the End Game widget, but to no avail :frowning:

Hey!

I see that you have SetStartDelay and Countdown functions. But I don’t see them actually called anywhere. Did you just leave those calls out of the post? In your GameStartWidget I see the Countdown function call node, but it never actually gets run cause there’s no execution flow going into it. Without seeing your whole project, for one I’m not sure why you need a SetStartDelay function that only calls a single node, you could simplify that and just call the “Set” StartDelay node without calling a function that calls the Set node. Second find a BeginPlay node that makes sense (again, not sure what your project looks like, how, when you want to start the countdown) and connect the Countdown function node to the BeginPlay node. EventConstruct is called even in the editor, but also when you start the game before the BeginPlay - we usually put game logic in BeginPlay vs EventConstruct (these are more for setups, stuff you already want to see in the editor before even playing the game)

Let me know how you get on!

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

}

There’s no execution after you create the widget

Great! With that execution taken care of, I am getting the InitialiseText function working fine, however no countdown is occurring. The ‘Get Ready’ text just stays on the screen now. I imagine the problem is at Initialise Text or at the Countdown functions:

The text is being set however I don’t think Set Time by Function Name is being called. Either that or there’s an issue I’m not seeing in Countdown:

Hmm… I don’t see anything glaringly obvious… I am a bit skeptical about the TextCountdown variable, in InitialiseText are you setting it to itself? Why? Or are they separate vars, then name them a bit different, you might be calling functions on different variables. Put some PrintStrings here and there to see where execution is/is not flowing, print out the variables to make sure they are what you expect them to be.
If you’re still stuck, let us know what you tried and a little more info - I think it’ll be in the BP vs code.

The TextCountdown Variable is the string that comes up showing the “Get Ready!” text. This should then change to a countdown until time expires, and then “Go!” comes up on the screen.

I don’t know what else I can do at this stage. This part of the course really confused me and I might end up restarting everything at this stage if I can’t find a solution. I don’t know where else to turn. Everything is EXACTLY as described in the lectures on the widget setups and there should be no issues in my code.

Only thing I can think of is that either your function name or the value you’re giving to SetTimer has a space in it. e.g.

Countdown[space]

I would do as @IzaBerry suggests and add a print statement at the start of Countdown to see if it’s ever being called.

Hi guys, so I solved it.

I passed a string to the output log just after printing out “Get Ready!”. The string came up, but then I got this warning:

The issue was that I was passing in TextCountdown into the Set Timer by Function Name. Once that was removed, everything worked as intended! For anyone who might have this issue, this is how the widget for InitialiseText should look like:

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

Privacy & Terms