What is the best way to handle Saving/Loading an Array of Objects?

#The << Operator

“something built-in that would do the transforms, materials, etc.”

Check out ArchiveBase and Archive.h

If you have a UE4 type, try using the << operator on it!

Transforms, Materials, Etc should all be covered by the << operator already.

Then for your class you define your own use of the << operator, which uses the existing UE4 type << usage

Here’s an example:

//JSMA
USTRUCT()
struct FRedStruct
{
	GENERATED_USTRUCT_BODY()

	//Vars
	UPROPERTY()
	int32 					VictoryVibe;
	
	UPROPERTY()
	FTransform 			VictoryTransform;
	
	UPROPERTY()
	FName 				MeshPath;

	UPROPERTY()
	bool StartsDisabled;
	
	//default properties
	FRedStruct()
	{
		VictoryVibe = 0;	
		MeshPath = FName(TEXT(""));
		StartsDisabled = false;
	}
};


										//could use a class instead of struct
FORCEINLINE FArchive &operator <<(FArchive &Ar, FRedStruct& TheStruct )
{
	Ar << TheStruct.VictoryVibe;
	Ar << TheStruct.VictoryTransform;
	Ar << TheStruct.MeshPath;
	Ar << TheStruct.StartsDisabled;
		
	return Ar;
}

#Spawn and Load

Final step when loading is to spawn fresh copy of class and then use the << operator on it! (or fresh struct)

#Enjoy!

:slight_smile:

Rama

1 Like