Reading text file in Unreal Engine 4

Something that really bug me is inability of ue4 to handle or read simple text file. Yes, you still can do this. But, what if I want to do is just put simple file text and read that as a string. You can do that in C++ using

For the purpose of this tutorial, we will create text file reader as a actor component. We need a method to read file that will be called from blueprint.

Create class actor component

Name it “TextReaderComponent”.

Put this code in your header & implementation files.

UFUNCTION(BlueprintCallable) FString ReadFile(FString filename); 
FString UTextReaderComponent::ReadFile(FString filename)
	//Read file ini [project]/Content/Data/ 
        //you can change with other location
	FString directory = FPaths::Combine(FPaths::GameContentDir(), "Data");
	FString result;
	IPlatformFile& file = FPlatformFileManager::Get().GetPlatformFile();
	if (file.CreateDirectory(*directory)) {
		FString myFile = directory + "/" + filename;
		FFileHelper::LoadFileToString(result, *myFile);
	return result;


Compile in both Editor & Visual Studio.


Create text file in Content/Data/file.txt. Fill it with whatever text you want. Add Component “Text Reader” in your actor. Drag component to Event Graph. Now you can read simple text file.

6 thoughts on “Reading text file in Unreal Engine 4”

  1. Does this read the entire text file into RAM?

    I want to read large text files, and walk over them line by line. I can probably split on the newline character into a string array.

  2. v.s. shows that:
    ; are undefined, what is needed to include in the TextReaderComponent.cpp ?

  3. FString directory = FPaths::Combine(FPaths::GameContentDir(), “Data”);
    Should be
    FString directory = FPaths::Combine(FPaths::GameContentDir(), TEXT(“Data”));

  4. I don’t understand the last step. What type should this component be? How am I supposed to make this work? I can’t use an Actor, which I am sure of.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.