UE 4.5.1 Saving Loading Custom USTRUCT()

I am currently making a login/registering system for my game and i am following along with Rama’s “Custom Save Systems, Write Any Data to Compressed Binary Files”. I am was wondering if it was possible and how if i can save my own custom UStruct to a compressed Binary File.

So far i have gotten most of the logic down, but i am getting an error here:

void AMyGameMode::SaveLoadData(FArchive& Ar, TArray<FPlayerRegisterInfo>& SaveDataArray)
{
	Ar << SaveDataArray;
}

“binary ‘<<’ : no operator found which takes a right-hand operand of type ‘FPlayerRegisterInfo’ (or there is no acceptable conversion)”

I’m good with logic, but i’m still trying to get used to UE’s variable conversions. Anyone know any solutions?

#Define << Operator for Your UStruct

You need to define the << operator for your custom UStruct!

Put this in a .h file where you define your core types, use your custom struct FPlayerRegisterInfo and all its members

#Solus Example

FORCEINLINE FArchive &operator <<(FArchive &Ar, FSolusApexDamage& TheStruct )
{
	Ar << TheStruct.Name;
	Ar << TheStruct.DamageAmount;
	Ar << TheStruct.HitLocation;
	Ar << TheStruct.ImpulseDir;
	Ar << TheStruct.ImpulseStrength;
	
	return Ar;
}

Enjoy!

Rama

Rama to the rescue. Thanks works perfectly now :).

Idk if it sounds obvious, but I’d like to point out things that still took me some time to figure out

  1. the << operator should be a friend function
  2. if you are saving a TArray of ustructs, their properties must be marked with UPROPERTY.