Loading text to a string

I’m trying to load text from a .txt file to a string, to use in my level blueprint. To test this, when pressing the q key some words from my text file should be printed ot the screen. However, nothing happens.

Any ideas where I’m going wrong? Here’s the code:

.CPP

#include "MuseumProject.h"
#include "MyBlueprintFunctionLibrary.h"


// Load and save text files
bool UMyBlueprintFunctionLibrary::FileSaveString(FString SaveTextB, FString FileNameB)
{
	return FFileHelper::SaveStringToFile(SaveTextB, *(FPaths::GameDir() + FileNameB));
}

bool UMyBlueprintFunctionLibrary::FileLoadString(FString FileNameA, FString& SaveTextA)
{
	return FFileHelper::LoadFileToString(SaveTextA, *(FPaths::GameDir() + FileNameA));
}


FString UMyBlueprintFunctionLibrary::FileLoadAndReturnString(FString FileNameA)
{

	FString myString;
	bool myBool = true;

	myBool = FFileHelper::LoadFileToString(myString, *(FPaths::GameDir() + FileNameA));
	return myString;
}

.H

#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyBlueprintFunctionLibrary.generated.h"

UCLASS()
class MUSEUMPROJECT_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	public:

	
	UFUNCTION(BlueprintCallable, Category = "save")
		static bool FileSaveString(FString SaveTextB, FString FileNameB);

	UFUNCTION(BlueprintPure, Category = "save")
		static bool FileLoadString(FString FileNameA, FString& SaveTextA);
	

	UFUNCTION(BlueprintCallable, Category = "save")
		static FString FileLoadAndReturnString(FString FileNameA);
	
};

The Blueprint

Coding is not my strong point so any help is appreciated.

Thank you! - SB7

Some debug information would help you and the rest of us get started - If you set a breakpoint within your FileLoadAndReturnString function in C++, is the breakpoint triggered?

If not, you should set a breakpoint on the Q Pressed event node in Blueprint. There are a few things that can screw up input.

Without knowing where things are going wrong, it’s harder to offer solutions.

Nevermind I was an idiot. It turns out the text files have to be in the project directory and not just anywhere on the drive! The code works fine after all, case closed. :slight_smile: