Download

how do i import a text file into unreal???

So im making agame like scrabble, and it needs to be able to check if a word is a real word or not. Instead of typing every single word in the dictionary into a String arrray, im trying to get it from a text file. I found this https://github.com/dwyl/english-words
but every time i try to drag in a csv or json file unreal automatically thinks its a table. I have even tried to import them as tables in every different combination of settings and unreal still wont import the data from them. How can I get a list of words from a text file into the engine? the file type doesnt matter.

If you can get each word into its own row on a table (spreadsheet) then save the table as a “comma delimited” file type (using ms excel or some other program), then create a struct asset in unreal that holds just a namespace, then import the table.

thanks for the reply, but the problem is this is for EVERY word in the dictionary, I cant sit here and type up a different row a billion times, i just cant.

You are going to have to write a script to handle that part for you.

The way I would do this is probably by having a C++ function that reads the file and return an array or a set.
Then I would use it to set the value of your object while still being in the editor.

You can use the Victory Plugin to do this, or, if you want to have your own version of this function, here it is:




bool UVictoryBPFunctionLibrary::LoadStringArrayFromFile(TArray<FString>& StringArray, int32& ArraySize, FString FullFilePath, bool ExcludeEmptyLines)
{
    ArraySize = 0;

    if(FullFilePath == "" || FullFilePath == " ") return false;

    //Empty any previous contents!
    StringArray.Empty();

    TArray<FString> FileArray;

    if( ! FFileHelper::LoadANSITextFileToStrings(*FullFilePath, NULL, FileArray))
    {
        return false;
    }

    if(ExcludeEmptyLines)
    {
        for(const FString& Each : FileArray )
        {
            if(Each == "") continue;
            //~~~~~~~~~~~~~

            //check for any non whitespace
            bool FoundNonWhiteSpace = false;
            for(int32 v = 0; v < Each.Len(); v++)
            {
                if(Each[v] != ' ' && Each[v] != '
')
                {
                    FoundNonWhiteSpace = true;
                    break;
                }
                //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            }

            if(FoundNonWhiteSpace)
            {
                StringArray.Add(Each);
            }
        }
    }
    else
    {
        StringArray.Append(FileArray);
    }

    ArraySize = StringArray.Num();
    return true;
}



I tried this, it gave me an error that said it didnt know what the UVictoryPluginLibrary was, even after i installed it and added it to the project.

  • Chuck the text in a csv file and drag drop into the content browser.
  • Before you do, prepare a struct that reflects the columns in the file.
  • This will automagically create a data table.
  • In case the engine starts choking when dealing with *billion *entries, consider splitting the list into separate tables alphabetically.

Once you have a data table you can loop through the content and parse it any way you want. You need a string array? Sure:

The list from your link is 460000+ entries or so - I had to increase loop iteration count to make it work. I used the basic words.txt file from the github you linked. Seems to load fine although there are 20 or so duplicate entries which the engines skips anyway.

Do tell if it’s not behaving like you expect.

thats exactly the type of working around im looking for! but

when i try to inport the csv file, this pops up, what am i supposed to import it as?

Edit: Do this AFTER you make the structure, got it! its working! thank you!, though, the Get Data Table Row part didnt work, had to just take the array element from the first for each loop and convert them to strings to get it working, but it works! thanks again!