Error Assertion failed: !bHasBegunPlay

After modifying BullCowCartridge to add EndGame() function, the entire project crash after showing me the message of end game. I have tried to check where could it be the error but i can’t find out, google doesn’t seem to have an answer to this neither.

BullCowCartridge.cpp

// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"
#include <string>

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    ClearScreen();
    PrintLine(TEXT("Preparado para jugar un poco\ncon el lenguaje?"));
    PrintLine(TEXT("Recuerda no usar acentos,\nno queremos desperdiciar tinta en eso."));

    SetupGame();

    PrintLine(FString::Printf(TEXT("Tienes %i vidas"),PlayerLives));
    FString StartMessage = FString::Printf(TEXT("Palabra de %i letras"), HiddenWord.Len());
    FString InputQuestion = TEXT("¿Cuál es la palabra escondida?\nIntroduce tu respuesta:");
    PrintLine(StartMessage);
    PrintLine(InputQuestion);
}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    /**
     * GAME LOOP
     * 
     * 1 Se establece la palabra secreta
     * 2 Se da la pista sobre la palabra secreta
     * 3 Se pide input
     * 4 Se da feedback sobre la respuesta
     * 5 Si es correcta ganas y si es incorrecta pierdes una vida
     * 
     * **/

    if (bGameOver)
    {
        BeginPlay();
    }
    else
    {
        ClearScreen();
        if (Input == HiddenWord){
            PrintLine(TEXT("Acertaste!"));
            EndGame();
        }else{
            --PlayerLives;
            if (PlayerLives > 0)
            {
                PrintLine(FString::Printf(TEXT("Oh... has fallado, te quedan %i intentos"), PlayerLives));
                if (HiddenWord.Len()!=Input.Len())
                {
                    PrintLine(FString::Printf(TEXT("La palabra solo tiene %i letras, intentalo de nuevo!"), HiddenWord.Len()));
                }
            }
            else{
                EndGame();
            }

        }

        /**
         * Check isogram
         * check number of characters
         * 
         * remove life
         * 
         * check lifes > 0
         * yes: Guessagain
         * no: Mostrar respuesta y playAgain
         * 
         *      enter to playAgain
         *      check user input
         *      play again or quit
         * 
         * 
         * 
         * 
         * */
    }
    


}

void UBullCowCartridge::SetupGame()
{
    HiddenWord = TEXT("Bufalo");
    PlayerLives = HiddenWord.Len();
    bGameOver = false;
}

void UBullCowCartridge::EndGame()
{
    PrintLine(FString::Printf(TEXT("Has perdido, la palabra era %s\n pulsa ENTER para jugar de nuevo"), *HiddenWord));
    bGameOver = true;
}

BullCowCartridge.h

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

#pragma once

#include "CoreMinimal.h"
#include "Console/Cartridge.h"
#include "BullCowCartridge.generated.h"

UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class BULLCOWGAME_API UBullCowCartridge : public UCartridge
{
	GENERATED_BODY()

	public:
	virtual void BeginPlay() override;
	virtual void OnInput(const FString& Input) override;
	void SetupGame();
	void EndGame();

	// Your declarations go below!
	private:
	
    FString HiddenWord;
	int32 PlayerLives;
	bool bGameOver;
};

CrashLog

UE4Editor_Core
UE4Editor_Core
UE4Editor_Core
UE4Editor_Core
UE4Editor_Engine
UE4Editor_BullCowGame_6325!UCartridge::BeginPlay() [D:\VideoGamesProjects\BullCowGame-starter-kit\Source\BullCowGame\Console\Cartridge.cpp:11]
UE4Editor_BullCowGame_6325!UBullCowCartridge::BeginPlay() [D:\VideoGamesProjects\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp:8]
UE4Editor_BullCowGame_6325!UTerminal::AcceptInputLine() [D:\VideoGamesProjects\BullCowGame-starter-kit\Source\BullCowGame\Console\Terminal.cpp:143]
UE4Editor_BullCowGame_6325!UTerminal::OnKeyDown() [D:\VideoGamesProjects\BullCowGame-starter-kit\Source\BullCowGame\Console\Terminal.cpp:112]
UE4Editor_BullCowGame_6325!TBaseUObjectMethodDelegateInstance&lt;0,UTerminal,TTypeWrapper&lt;void&gt; __cdecl(FKey)&gt;::Execute() [C:\FastEpicGamesLibrary\UE_4.22\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:617]
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Core
UE4Editor_Core
UE4Editor_Core
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll

I found the solution.

I was calling BeginPlay() after losing all lives. This seems to be a problem because BeginPlay has to do some engine related tasks. Calling it twice recreates something that is needed at all times causing the game to crash.

I have solved the problem moving all the content of BeginPlay() to SetupGame(), and calling SetupGame() instead.

I’m still curious about what the BeginPlay() does behind the scene so if anyone knows, please explain me what is checking or doing UActorComponent::BeginPlay() when super::BeginPlay() is triggered.

You can’t call BeginPlay. BeginPlay can only be called once and is done so by the engine when the game begins or the actor is spawned.

That is why you are receiving that message. The engine checks !bHasBegunPlay when it is called and if it has begun play would mean this fails.

1 Like

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

Privacy & Terms