Download

Need help with binary saving

Hey everyone!
I mainly work in blueprints but I do some things like algorithms in c++. My main base classes are also in c++.

I try to create a binary save system following Rama’s tutorial but I’m stuck at the operator << overloads
When I try to save my data it crashes when trying to save a struct. When I comment out the line for the struct it works and the function saves the vector2d and the fstring.



//This is my custom struct
USTRUCT(BlueprintType)
struct FBattleMapTileData
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Battle Map Data")
		TSubclassOf<AMapTile> TileType;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Battle Map Data")
		FTransform TileTransform;
};



Now the struct is used in an array and this is how my overload looks like:


FORCEINLINE FArchive& operator<<(FArchive &Ar, FBattleMapTileData TileData)
{
	Ar << TileData.TileType;
	Ar << TileData.TileTransform;

	return Ar;
}


And finally, this is the conversion function:


//SaveLoadData
void ABattleMapCreator::SaveLoadData(FArchive& Ar, TArray<ABattleMapData*> BattleMapData)
{
	UE_LOG(BattleMapCreator, Log, TEXT("Attempting binary conversion."));

	for (ABattleMapData* map : BattleMapData)
	{
		Ar << map->MapSize;
		Ar << map->MapName;
		//Ar << map->MapData;
		for (FBattleMapTileData tile : map->MapData)
		{
			Ar << tile;
		}
		
	}

	UE_LOG(BattleMapCreator, Log, TEXT("Converted to binary!"));
}


I hope someone can help me! Thanks!

EDIT: Ok, apparently there is a problem with saving a TSubclassOf type. Is there a way do this?

hi, I know this is an old thread but have you found any solutions to it? I’m kinda guessing that you can’t save classes that do not define the << operator.

Hey @RowelCaps ,
I can’t remember if I managed to fix that error, sorry.

I helped resurrect the Wikiwhen it went down. Alot of the content there was outdated. I remember a section in this courseon save games (in Light Painter project) but there are other places you could find it.

Main point: I wouldn’t stick to that wiki by Rama as the only way to do it. I find Matthew Wadstien fun to watch because UE does so much I often feel “HTF” working with it :slight_smile: