[Question]/[Request] File IO Exposure

Hello!

We need to implement File IO as soon as possible, but very little seems to be available in Rocket (or maybe I just need pointing in the right direction - I’m working somewhat from memory and some things may have changed?). One of our objectives is to be able serialise and deserialise entire UObjects from both binary and text formats.

We can use the ExportText / ImportText to create T3D representations of our UObjects which is great. If possible it would be nice to have a more common data structure and I know there are ways to translate T3D text to and from Json already built into UE4 (FJsonObjectConverter) - it would be nice to also see XML support given that there are XML utilities hidden somewhere away from Rocket users too.

Our main issue is how to read and write this text to and from disk. UE4 should already have this functionality (FileHelper?), but it does not seem to be exposed to Rocket either. FileManager does seem to be able to serialise text, but it will only serialise in Unicode and includes a lot of additional serialisation data, rendering it unusable in a practical environment.

A bigger issue is that of binary data - there’s little useful currently available to Rocket users. We can export binary data via UExporter, but there seems little in the way of reading it back in? Should we expect to be using the FileManager and create FileReaders / FileWriters and create and use archives? Is there any kind of example we could be looking at to achieve this end?

Summary:

  1. Expose JsonUtilities and XML handling to Rocket users. Being able to input and output to a standard human-readable data structure is pretty handy. UDK users had access to similar functionality included in this example development kit gem, which was used by many people:
    UDK | DevelopmentKitGemsSaveGameStates

  2. Expose FileHelper or an equivalent to Rocket users to allow writing out plain text files more easily.

  3. Clarify the process for serialising and deserialising Uobjects as binary data, and if anything required for this process isn’t available to Rocket users, expose it.

Thanks!

Luke

Side note - your tagging system is broken and claiming tags from the suggested drop down don’t exist.

Dear Luke,

“A bigger issue is that of binary data - there’s little useful currently available to Rocket users. We can export binary data via UExporter, but there seems little in the way of reading it back in? Should we expect to be using the FileManager and create FileReaders / FileWriters and create and use archives? Is there any kind of example we could be looking at to achieve this end?”

#You are In Luck

I will write you up a tutorial on this, so everything I write below I am saying cause I’m going to explain shortly how to do it.


I have been writing out and reading back in binary files for months now, for my in-game editor.

I am capable currently of writing out and reading in my own custom classes and all relevant data, and I already have a working level saving and level loading features of

  • position data
  • class-specific properties of any kind
  • CUSTOM MATERIALS created during run time by modifying dynamic material instanceproperties
  • basically any data I could ever want

#Zipping

Not only am I writing out any data I want as binary files, I am also ZIPPING it using the provided ZLIB functionality of UE4.

#Text

“Expose FileHelper or an equivalent to Rocket users to allow writing out plain text files more easily.”

I already posted a tutorial and provided the entire C++ code for saving text to a human-readible non-binary file

here is that tutorial and code:

http://forums.epicgames.com/threads/972861-TUTORIALS-C-for-UE4-gt-gt-New-Equivalent-of-PostInitComp-amp-Tick-for-Anim-Blueprints?p=31682322&viewfull=1#post31682322

#Saving .BMP files

I also wrote up a tutorial on saving screen shots, here is my entire C++ code for custom screenshot saving system

http://forums.epicgames.com/threads/972861-TUTORIALS-C-for-UE4-gt-gt-New-VIDEO-Entire-Projectile-Class-Code-Accel-amp-Bounces?p=31676249&viewfull=1#post31676249

#Summary

Again I wrote all this to let you know it is all possible and easy to do

I am going to write up a tutorial as speedily as I can to explain

  • creating binary files and saving any arbitrary data of your choosing
  • reading back in this binary files from hard disk
  • creating compressed binary files using ZLIB functionality of UE4

#:heart:

Rama

PS: for anyone reading this I hope it’s clear I’m not “showing off,” I am indicating it is all very very do-able, I’ve been doing it for months.

Aha! Looks like FileHelper is indeed exposed reading throug your text example. Note sure how I missed it when I looked.

I look forward to your binary file tutorial :slight_smile:

Thanks!

Luke

#Yay!

Glad I could help out!

Below is my tutorial showing how to write and read compressed binary files containing any data of your choosing.

I also discuss overloading the << operator to make this process very easy.

#Tutorial Finished

For the sake of those looking on the UDN in the future,

Here is the link!

Writing and Reading Compressed Binary Files of Any Data of Your Choosing

http://forums.epicgames.com/threads/972861-41-TUTORIALS-C-for-UE4-gt-gt-New-Make-a-Custom-C-Save-System-to-Compressed-Binary?p=31782451&viewfull=1#post31782451

#Sample Code

A small sample from the tutorial:

#Saving Compressed Binary

   bool ControllerClass::SaveGameDataToFileCompressed(const FString& FullFilePath, 
	int32& SaveDataInt32,
	FVector& SaveDataVector,
	TArray& SaveDataRotatorArray
){
	FBufferArchive ToBinary;
	SaveLoadData(ToBinary,NumGemsCollected,PlayerLocation,ArrayOfRotationsOfTheStars); 
	
	//Pre Compressed Size
	ClientMessage("~ PreCompressed Size ~");
	ClientMessage(FString::FromInt(ToBinary.Num()));
	
	//~~~
	
	//~~~ Compress File ~~~
	//tmp compressed data array
	TArray CompressedData;
	FArchiveSaveCompressedProxy Compressor = 
		FArchiveSaveCompressedProxy(CompressedData, ECompressionFlags::COMPRESS_ZLIB);
	
	//Send entire binary array/archive to compressor
	Compressor << ToBinary;
	
	//send archive serialized data to binary array
	Compressor.Flush();
	
	//~~~
	
	//Compressed Size
	ClientMessage("~ Compressed Size ~");
	ClientMessage(FString::FromInt(CompressedData.Num()));
	
	
	if (!GFileManager) return false;
	
	//vibes to file, return successful or not
	if (FFileHelper::SaveArrayToFile(CompressedData, * FullFilePath)) 
	{
		//~~~ Free Binary Arrays ~~~
		Compressor.FlushCache();
		CompressedData.Empty();
		
		ToBinary.FlushCache();
		ToBinary.Empty();
		
		//~~~ Close Buffer ~~~
		ToBinary.Close();
		
		ClientMessage("File Save Success!");
		
		return true;
		//~~~~~~~~~~~~~~~
	}
	else
	{
		//~~~ Free Binary Array ~~~
		ToBinary.FlushCache();
		ToBinary.Empty();
		
		//~~~ Close Buffer ~~~
		ToBinary.Close();
		
		ClientMessage("File Could Not Be Saved!");
		
		return false;
		//~~~~~~~~~~~~~~~
	}
}

Hello,I have looked up this Tutorial ,but there is a question I can’t understand is how can I create a Blueprint from the file in hard disk , I see the data types you can save to hard disk are all variables , not a Object , I tried to save UObject* to the hard disk by your way , but it seems like the UE4 Engine don’t support it (means the “<<” operator can’t do it).So what should I do,THANKS.

Hi Attack,

This is an archived post from our beta of UE4 that is no longer being tracked. Some or all information posted here is outdated. If you want you can post this as a new question on the AnswerHub and link here for reference.

Thank you!

Tim

I am not in luck, because even though I can register for the epicgames forums, I do not have permission to view those articles. So, no dice.