Hello,
I’ve figured out how to export a CSV file containing a String array during runtime, but I’m not sure how to make this function work for a structure-based array. If it’s important, my structure contains a transform, a float, a float, and a bool, in that order. I’d eventually like to import this data into a different project and be able to use the transform variable data, the float variables’ data, etc. I’m still quite new to C++, so specific suggestions would be appreciated!
Here’s the C++ that works for the String array:
*TextFileManager.cpp:*
#include "TextFileManager.h"
#include "Misc/FileHelper.h"
#include "HAL/PlatformFilemanager.h"
bool UTextFileManager::SaveArrayText(FString SaveDirectory, FString FileName, TArray<FString> SaveText, bool AllowOverwriting = false)
{ //set complete file path
SaveDirectory += "\\";
SaveDirectory += FileName;
if (!AllowOverwriting)
{
if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*SaveDirectory))
{
return false;
}
}
FString FinalString = "";
for (FString& Each : SaveText)
{
FinalString += Each;
FinalString += LINE_TERMINATOR;
}
return FFileHelper::SaveStringToFile(FinalString, *FSaveDirectory);
–
*TextFileManager.h:*
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "TextFileManager.generated.h"
/**
*
*/
UCLASS()
class GHOSTCARDEMO_API UTextFileManager : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable, Category = "Custom", meta = (Keywords = "Save"))
static bool SaveArrayText(FString SaveDirectory, FString FileName, TArray<FString> SaveText, bool AllowOverwriting);
};
–
If you have any ideas, it’d be much appreciated. I’m strugglin with this one. Thank you!