Custom saving system with USTRUCT

Hi!

I have been trying to follow Rama’s tutorial for making a custom save system, and I’ve managed to run into a few problems. I am currently trying to save a custom USTRUCT to a file, with some properties that are difficult to serialize.

USTRUCT(BlueprintType)
struct FPaintingLayer
{

	GENERATED_BODY()

	uint8 * layerColors;
	uint32 layerDataSize;
	UMaterialInstanceDynamic * layerMaterialInstance;
	UTexture2D * layerTexture;
	int layerID;
	float layerOpacity;
	bool layerVisible;
};

I have implemented an operator overload for << that can accept my custom USTRUCT. Unfortunately, when it tries to serialize the material instance, i run into this assertion from MemoryArchive.h:

virtual FArchive& operator<<( class UObject*& Res ) override
{
	// Not supported through this archive
	check(0);
	return *this;
}

I was using an FBufferArchive as in the tutorial example, and i assume that this specific archive is unable to read objects. I would also assume that FObjectReader and FObjectWriter would be better picks for this, however, these are unable to handle the other properties of the USTRUCT. Is there a way to implement the usage of both the FBufferArchive and the object reader/writer somehow, so that i can serialize the object properties in the structure?