Problem with loading HiddenWordList.txt into TArray

I have tried to follow the instruction to load the list of String into TArray.
The HiddenWordList.txt is stored under WordLists in Content File.
And I also add the WordLists directory to the list of Additional Non-Asset Directories

When I try to print the loaded list but found the size is empty. (seems it fails to load the file into the array)
I also found that the path was a relative path instead of absolute path, not sure if it is related.
But I also tried to replace it with absolute path but still can’t fix the issue

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

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    const FString WordListPath = FPaths::ProjectContentDir() / TEXT("WordLists/HiddenWordList.txt");
    bool bSuccess = FFileHelper::LoadFileToStringArray(FileWordList, *WordListPath);

    PrintLine(TEXT("Path : %s"), *WordListPath);
    PrintLine(TEXT("FileWordList size : %i"), FileWordList.Num());
    
    if (bSuccess)
    {
        PrintLine(TEXT("Load success : True")); 
    }
    else
    {
        PrintLine(TEXT("Load success : False")); 
    }

    // SetupGame();
    // PrintLine(TEXT("The Hidden word is: %s."), *HiddenWord);
}



Do you have “hide known file extensions” in File Explorer enabled (it is by default)? If so that would mean your text file is actually ending with “.txt.txt” as the last .txt is being hidden.

1 Like

Thanks!! I have updated the configuration to show the extensions and it behaved as you suggest and it works now.

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

Privacy & Terms