FPaths::ProjectContentDir() return

Hello.

I have a problem with FPaths::ProjectContentDir() function on Windows 10. If my project is placed on non-system dick (D: in my case), this functiom returns something like “/…/…/…/…/…/” instead of disk letter. But if i copy my project on the system disk, it works normal. I checked if there are non-ASCII symbols in the pass to directory, but didn’t find any.

Disk D:

Disk C:

.cpp file:

#include "BullCowCartridge.h"
#include "Misc/FileHelper.h"
#include "Misc/Paths.h"



void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();

    const FString WordListPath = /* FPaths::ProjectContentDir() /  */TEXT("D:/UE4 - Udemy/BullCowGame-starter-kit/Content/WordList/HiddenWordList.txt");
    FFileHelper::LoadFileToStringArray(Words, *WordListPath);


    FString PrDir = FPaths::ProjectContentDir();
    PrintLine(TEXT("ProjectDir is: %s"), *PrDir);

    Isograms = GetValidWords(Words);

    SetupGame();    //Setting Up Game

}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    if (bGameOver){
        ClearScreen();
        SetupGame();
    }
    else{   //Checking player Guess
        ProcessGuess(Input);
    }
}

void UBullCowCartridge::SetupGame(){
    //Welcomming 
    PrintLine(TEXT("Welcome to the Bull Cows Game!"));
    PrintLine(TEXT("Good Luck!"));
    HiddenWord = Isograms[FMath::RandRange(0, Isograms.Num()-1)];
    
    Lives = HiddenWord.Len() * 2;
    bGameOver = false;

    PrintLine(TEXT("Guess the %i-letter word."), HiddenWord.Len());
    PrintLine(TEXT("You have %i attempts"),Lives);
    PrintLine(TEXT("Type in your guess"));
    PrintLine(TEXT("Then press enter to continue..."));
    PrintLine(TEXT("Hidden word is: %s"), *HiddenWord);
    const TCHAR HW[] = TEXT("cake");
}


void UBullCowCartridge::EndGame(){
    bGameOver = true;
    PrintLine(TEXT("The Hidden Word is %s"), *HiddenWord);
    PrintLine(TEXT("Press enter to play again..."));
}


void UBullCowCartridge::ProcessGuess(const FString& Guess){
    if (Guess == HiddenWord){
        ClearScreen();
        PrintLine(TEXT("Congratulations, you have won!"));
        EndGame();
        return;
    }


    if (HiddenWord.Len() != Guess.Len()){
        PrintLine(TEXT("The Hidden Word is %i character word, try again."), HiddenWord.Len());
        PrintLine(TEXT("You have %i attempts."), Lives);
        return;
    }
    
    if (!IsIsogram(Guess)){
        PrintLine(TEXT("Your word isn't an isogram."));
        PrintLine(TEXT("You have %i attempts."), Lives);
        return;
    }

    Lives--;
    PrintLine(TEXT("Your guess is wrong. Try again."));
    if (Lives <= 0){  
        EndGame();
        PrintLine(TEXT("You have lost. Better luck next time!"));  
        return;
    }
    int32 Bulls = 0;
    int32 Cows = 0;
    GetSkullSpider(Guess, Bulls, Cows);

    PrintLine(TEXT("You have %i bulls and %i cows."), Bulls, Cows);
    PrintLine(TEXT("Guess again, you have %i more attempts."), Lives);
    
}

bool UBullCowCartridge::IsIsogram(const FString& Word) const{

    for(int32 Index = 0, Comparison = Index + 1; Index < Word.Len(); Index++){
        for(Comparison = Index + 1; Comparison < Word.Len(); Comparison++){
            if (Word[Index] == Word[Comparison]){
                return false;
            }
        }
    }


    return true;
}

TArray<FString> UBullCowCartridge::GetValidWords(const TArray<FString>& WordList) const{
    TArray<FString> ValidWords;
    for(FString Word : WordList){
        if(Word.Len() >= 4 && Word.Len() <= 8){
            if(IsIsogram(Word)){
                ValidWords.Emplace(Word);
            }
        }
    }
    return ValidWords;
}

 void UBullCowCartridge::GetSkullSpider(const FString& Guess, int32& SkullCount, int32& SpiderCount) const
{
    SkullCount = 0;
    SpiderCount = 0;

    for (int32 GuessIndex = 0; GuessIndex < Guess.Len(); GuessIndex++)
    {
        if (Guess[GuessIndex] == HiddenWord[GuessIndex])
        {
            SkullCount ++;
            continue;
        }
        for (int32 HiddenIndex = 0; HiddenIndex < HiddenWord.Len(); HiddenIndex++)
        {
            if (Guess[GuessIndex] == HiddenWord[HiddenIndex])
            {
                SpiderCount ++;
                break;
            }
        }
    }
} 

Header file:


#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();
	void ProcessGuess(const FString& Guess);
	bool IsIsogram(const FString& Word) const;
	TArray<FString> GetValidWords(const TArray<FString>& WordList) const;
	void GetSkullSpider(const FString& Guess, int32& SkullCount, int32& SpiderCount) const;

	// Your declarations go below!
	private:
	FString HiddenWord;
	int32 Lives;
	bool bGameOver;
	TArray<FString> Words;
	TArray<FString> Isograms;
};

Any help is appreciated.

Is that causing you problems? “..” just means the parent directory.

If the current working directory is

C:\Users\Dan

Then .. means

C:\Users

Yes, it causes a problem. If I try to open the file using
FPaths::ProjectContentDir() / TEXT("WordList/HiddenWordList.txt");
path, there is no file and project crashes. I guess, “…/…/…/…/…/…/” is the path from “UE4Editor.exe” file.

I tried to run this commands in another project and it works. I’m not sure, what was wrong in BullCowGame project. I guess, it is connected with numer of ‘/’ symbols.

Thanks for your help.

It might have been due to a large path name. Not sure why that happened though :man_shrugging:.

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

Privacy & Terms