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.

  1. Create class actor component

    Name it “TextReaderComponent”.

  2. Put this code in your header & implementation files.


  3. Compile!

    Compile in both Editor & Visual Studio.

  4. Testing.

    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.

3 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:
    UTextReaderComponent
    ,FPlatformFileManager
    ,FFileHelper
    ,FPaths
    ; 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”));

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.