Word bank '.txt' file to string array

I’m currently doing a project which involves the user typing words to enable progression. It is a simple arcade game in which words come at you and you type them to destroy/avoid them. As of right now, I have a “hard coded” string array from which the game randomly picks up a word. I am also fairly new to C++ programming within UE4. Never ran into a limitation of blueprints until now.

My question is this, How can a read a .txt and parse every line into a string array? Can I use the standard C++ fstream library and cin >> loop my file, if so how inside UE4? (The file has a word per line) Also if this works how can I integrate this array to the already existing logic I have with Blueprints, should I worry about this?

I really appreciate the help and the time.

(small image and link to devlog, probably will help in some way if the question wasn’t clear enough)


[Devlog link][2]

If no one will answer for this I will give you code when I will come back home. (2h from now). I used it to load localization text for Ben The Exorcist, so I think that this will help you.

You can create data tables in unreal - you can do this in c++ or blueprint (its really easy in blueprint)

then you can import CSV or JSON data into them, you can also export it back to these formats so you can manage the data and re-import

I would appreciate that, thank you

From C++ you can use something like this:

bool ABaseLevel::FileLoadString(FString FileNameA, FString& SaveTextA)
{
	return FFileHelper::LoadFileToString(SaveTextA, *(FPaths::GameContentDir() + "Lang/" + FileNameA));
}

This will load a file in your game content direction in subfolder Lang

FString fileText;
FileLoadString(FileNameA, fileText);
if (fileText.IsEmpty())
	return;
TArray<FString> lines;
fileText.ParseIntoArrayLines(lines);

for (FString singleLine : lines)
{
	//Do some stuff
}
1 Like

Thanks so much, solved my problem