UnReal Crash when crete InitGame in BullCownCartidge.h file



Delete your Binaries and Intermediate folders and then try opening your project and rebuild when it asks.

The problem still there. Even when I declare HiddenWord in the header the program crashes.

The “BullCowCartridge.cpp” and BullCowCartridge.h" below:

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

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    PrintLine(TEXT("Welcome to Bull Cows!"));
    PrintLine(TEXT("Guess the 4 letter word!")); // Magic Number Remove!
    PrintLine(TEXT("Press enter to continue..."));
    HiddenWord = TEXT("cake");
}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    ClearScreen();
    //FString HiddenWord = TEXT("cake"); // Move outside this function.

    if (Input == HiddenWord)
    {
        PrintLine(TEXT("You have Won!"));
    }
    else
    {
        PrintLine(TEXT("You have Lost!"));
    }
    
}
// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    PrintLine(TEXT("Welcome to Bull Cows!"));
    PrintLine(TEXT("Guess the 4 letter word!")); // Magic Number Remove!
    PrintLine(TEXT("Press enter to continue..."));
    HiddenWord = TEXT("cake");
}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    ClearScreen();
    //FString HiddenWord = TEXT("cake"); // Move outside this function.

    if (Input == HiddenWord)
    {
        PrintLine(TEXT("You have Won!"));
    }
    else
    {
        PrintLine(TEXT("You have Lost!"));
    }
    
}

Thanks for your answer.

You’ve posted the same code twice. Did you mean for one of them to be the header?

Sorry, for the mistake. The other code should be the header which is posted below.

// 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;

	// Your declarations go below!
	private:
	FString HiddenWord;
};

The program still crashing. Did I reinstall the Unreal Engine to see if the problem disappears, but didn’t work.
The problem happens when I write the HiddenWord in the header file.

And it’s crashing on compilation?

Yes, it is crashing during the compilation

Well I’m not seeing anything wrong with that so try rebuilding by closing Unreal and then delete your project’s Binaries and Intermediate folders and then open the project.

Privacy & Terms