LoadFiletoString returns empty

So I’ve been trying to implement this tutorial: [Updating Data From a Text File at Runtime][1]

I was having issues compiling at first, but with the help of someone from here I was able to overcome that and get it to compile successfully and now the loadFileToString node is available in Blueprints. Unfortunately, it doesn’t seem to be working. I have the file in the proper directory. I have the node pointing to that file path. It is a text file that only contains the exact same two values separated by a comma from the tutorial: “.5,300”.

The only changes I have made to the code from the tutorial are changing “GameContentDir” to “ProjectContentDir” since the former was depreciated and replaced by the latter. That made the compiler happier. I have tried doing it as a level blueprint. I have tried dragging it in as an actor. No luck. It’s like getting a null response. No error. Just no data. Nothing prints. The node fires, but when it gets to the loop there is nothing to loop, so it just goes straight to completed without spitting out any data.

I feel like I am so close I can taste the victory, but alas - so close and yet so far. I know this should be possible, so what am I missing here?

Not sure what exactly the problem is but I just tried the code below and that worked:

308798-loadfile.png

It might also be an issue with how the Blueprint node passes the Filename to the method in c++.
You might want to try putting a breakpoint in VisualStudio inside the method and look at the content of “Filename”. There might be issues with how the " / " is handled.

Thank you for the response. I tried your code, and it compiled successfully, and promptly fires off the error message. I am trying to follow your suggestion to add a breakpoint inside the method, but once that’s done I assume I run the debugger, and from what I can gather I’m supposed to look in the autos section to see variable data, but nothing shows up there.

So unable to get the debugger working, I tried instead to test the \ by removing the directory component and putting the file directly into the Content folder. Still fires the error. I then out of sheer desperation tried going to C: and making an identical directory tree and sticking a file there to see if maybe it was just looking for the wrong drive. That failed as badly as expected. I’d like to be able to see the filename like you suggested, that would be helpful. Where would I find that?

Thank you for the response. I tried your code, and it compiled successfully, and promptly fires off the error message. I am trying to follow your suggestion to add a breakpoint inside the method, but once that’s done I assume I run the debugger, and from what I can gather I’m supposed to look in the autos section to see variable data, but nothing shows up there.

So unable to get the debugger working, I tried instead to test the \ by removing the directory component and putting the file directly into the Content folder. Still fires the error. I then out of sheer desperation tried going to C: and making an identical directory tree and sticking a file there to see if maybe it was just looking for the wrong drive. That failed as badly as expected. I’d like to be able to see the filename like you suggested, that would be helpful. How would I find that?

First of all, in VisualStudio, make sure that you have the “DebugGame Editor” build configuration selected. Otherwise, the c++ compiler might optimize away some variables and you won’t be able to see their value at runtime. Then you could try debugging with breakpoint again.

You could also add some logging to the method so all the paths and relevant information would be dumped into the console in the editor (you would not need the breakpoint in this case).

Like so:

FString URuntimeVariableBridge::LoadFileToString(FString Filename)
{
	UE_LOG(LogTemp, Warning, TEXT("Received Filename from Blueprint. Filename was: %s"), *Filename);
	
	FString directory = FPaths::ProjectContentDir();
	UE_LOG(LogTemp, Warning, TEXT("ContentDirectory: %s"), *directory);
	
	FString myFilePath = directory / Filename;
	UE_LOG(LogTemp, Warning, TEXT("MyFilePath: %s"), *myFilePath);
	
	FString result;
	if(FPaths::FileExists(myFilePath))
	{
		UE_LOG(LogTemp, Warning, TEXT("Found the file."));
		if(FFileHelper::LoadFileToString(result, *myFilePath))
		{
			UE_LOG(LogTemp, Warning, TEXT("Successfully loaded the file. Content was: %s"), *result);
			return result;
		}
		else
		{
			UE_LOG(LogTemp, Warning, TEXT("An error occured while attempting to load the file."));
		}
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("Unable to find file in specified directory."));
	}
	return FString("We have an error!");
}

This is getting really weird.

I didn’t know where I should check to see if I have select “Debug Game Editor” or not and when I googled it I wasn’t able to come up with anything, but I did manage to solve the issue of needing to see the variable by just throwing it into the error message in place of the string. The first time I did this, I had VS installed on C:, UE4 on D: and The Project on C:. So it threw the error with the wrong path, so I figured, OK, this is good. We just need to make sure it’s pointing to the right drive. So I copied the project to the other drive, and then it still threw an error, but this time the variable is pointing EXACTLY where my file is. But I don’t get the variables inside, I get an error.

At this point I decided that perhaps it’s because I’m trying to cross over from one drive to the next and maybe I’m hitting some invisible obstacle in the process. So I moved EVERYTHING over to C: drive. Created a completely new project, complete blank slate. Compile is good. I can use the node. My file is in place. I think this is it, this has got to be it. Everything is synced up. I run it, and it throws the error message with the incorrect path. I move the project to D: (Just the project) and now it gives me the url with the correct path, but still as an error message.

Everything is installed on C:, The project was created on C:, all the files are on C:, but for whatever reason it wanted to be on D:. So I create a brand new project but this time I have it created on D:. So I run through the entire exercise only to have the same result as when I just copied it.

I can not for the life of me figure out why it’s always looking on the other drive for the project even after a complete uninstall/reinstall cycle. Then when it does find it, it can’t read it.

I really can’t see where the issue is from your description.
Except for either the path being too long (255 characters is max if I remember correctly) or in the example where the project was on D:/ it might have issues with the space in the name “VR Project”.
But I doubt that any of this is the issue.

Could you copy the code I posted above (the one with the log messages) and execute it and then show us the log output please.

Absolutely. My apologies for not trying it earlier, I was overwhelmed. Got it working though, with the a similar result. Log shows it’s looking in the right place, it just can’t see it.

Hello. I am also trying this based on the tutorial but I have the same result as yours - it returns a blank result. Were you able to resolve this issue?

FYI don’t manually manipulate path strings. Use FPaths::Combine. It handles all the logic for you to ensure it works on the platform it’s running on.