1.新建一个c++ 文件,类型为BlueprintFunctionLibrary
RWTextFile.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "RWTextFile.generated.h"
/**
*
*/
UCLASS()
class CEXPAND_API URWTextFile : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintPure, Category = "Custom", meta = (Keywords = "LoadTxt"))
static bool LoadText(FString FileName, FString& OutText);
UFUNCTION(BlueprintCallable, Category = "Custom", meta = (Keywords = "SaveTxt"))
static bool SaveText(FString InText, FString FileName);
};
RWTextFile.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "RWTextFile.h"
#include "Runtime/Core/Public/Misc/FileHelper.h"
#include "Runtime/Core/Public/Misc/Paths.h"
bool URWTextFile::LoadText(FString FileNameA, FString& SaveTextA){
return FFileHelper::LoadFileToString(SaveTextA,*(FPaths::GameDir()+FileNameA)) ;
}
bool URWTextFile::SaveText(FString SaveTextB, FString FileNameB)
{
return FFileHelper::SaveStringToFile(FileNameB,*(FPaths::GameDir()+FileNameB));
}
2 在项目的根目录下新建一个文件
3 蓝图调用代码截图如下: