x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Need root directory for text file

I'm currently trying to load a text file from my games root directory, rather than having to give a full path to the function. My code at the moment is

     FString PathToLoad = "C:\\Users\\username\\Documents\\Unreal Projects\\GameTest\\TextFile.txt";
     if (!FPlatformFileManager::Get().GetPlatformFile().FileExists(*PathToLoad))
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("** Could not find file **"));
         return;
     }
     FFileHelper::LoadANSITextFileToStrings(*(projectDir), NULL, StringArray);

However, I want the path to already be at the root directory so I don't have to use the full path name all the time. I have tried to use the FPath::GameDir() but can't seem to get it working. Is there a way to do this so that I can use that to show where my project is and then grab the text file from there?

 FString PathToLoad = FPaths::GameDir();
 PathToLoad += "TextFile.txt";
Product Version: Not Selected
Tags:
more ▼

asked Apr 08 '14 at 12:21 PM in C++ Programming

avatar image

Dune
1.9k 52 38 200

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

I must have bee doing something wrong somewhere stupid, checked again and made some other changes:

Here is my code anyway:

 FString projectDir = FPaths::GameDir();
         projectDir += "Content/TextFile.txt";
         if (!FPlatformFileManager::Get().GetPlatformFile().FileExists(*projectDir))
         {
             GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("** Could not Find File **"));
             return;
         }
         FFileHelper::LoadANSITextFileToStrings(*(projectDir), NULL, StringArrat);

Which loads a file of strings on new lines into an array.

more ▼

answered Apr 08 '14 at 02:44 PM

avatar image

Dune
1.9k 52 38 200

avatar image MorskoyZmey Jul 21 '14 at 06:49 PM

Let me note that probably FPaths::GameDir() doesn't returns path with ending slash, thats why it might not worked

(comments are locked)
10|2000 characters needed characters left

what is GameDir() returning? it works great for me :)

more ▼

answered Apr 08 '14 at 01:47 PM

avatar image

Rama
10.6k 444 343 1081

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question