I’m working on a content-only project, and I need to save an array of strings to a text file locally.
I know this is possible with Rama’s plug-in as I have tried it, however as I understand it, I can’t use these plug-ins in a content only game when packaged? I get this error message when the plug-in is enabled and I try package the game:
Is there any other way to do this through blueprints without a plug-in, or how should I be doing it?
Thanks yRezaei, excuse my ignorance on this, but will this will work if I am working on a blueprint only project? i.e. no code. Do I still have a .h file for my project either way?
The base class and functions for writing text into a file exist in UE4. But unfortunately there is no blueprint callable function to access them. I am afraid, this is the only way, as far as I know.
Just found this amazingly useful! Thanks so much, yRazaei!
Thought I’d post my code to save anyone who needs this from having to type it all out again.
Cant seem to reply to the answer for some reason but all credit goes to yRazaei (except maybe for the typing!)
hope thats ok.
WriteToFile.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Paths.h"
#include "WriteToFile.generated.h"
/**
*
*/
UCLASS()
class UWriteToFile : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()
public:
UFUNCTION(BlueprintCallable, meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject", FriendlyName = "File-IO"), Category = "WriteToFile")
static bool FileIO__SaveStringTextToFile(FString SaveDirectory, FString fileName, FString SaveText, bool AllowOverWriting);
};
WriteToFile.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "LeapExamples.h"
#include "WriteToFile.h"
UWriteToFile::UWriteToFile(const class FObjectInitializer& PCIP)
:Super(PCIP)
{
}
bool UWriteToFile::FileIO__SaveStringTextToFile(FString SaveDirectory, FString fileName, FString SaveText, bool AllowOverWriting)
{
FString path;
path = FPaths::GameDir();
path += "/my_data";
if (!FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*path))
{
FPlatformFileManager::Get().GetPlatformFile().CreateDirectory(*path);
if (!FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*path))
{
return false;
}
}
path += "/";
path += fileName;
if (!AllowOverWriting)
{
if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*path))
{
return false;
}
}
return FFileHelper::SaveStringToFile(SaveText, *path);
}
It won’t work if you just copied and pasted, note that "#include “leapExamples.h” etc. should be replaced with your own project name, have you done this?