Serialize TSubclassOf<>

TSubclassOf MyClass;
FBufferArchive Ar;

Ar << MyClass;

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

Is there a way to serialize a class? I’ve thought of making classes enum but if there’s a way to serialize it, that would be better.

I’m getting same error but I think only way would be to do it through FString. So get class as FString and serializes that instead. My custom data that need to be serialized are suffering from this as well. Will post answer once I figure it out.

Serializer doesn’t seem to work on pointers. So I just created my own static function that convert a class to int before saving then convert it back to class when loading.

I ended up using FArchive and serializing my class as string path for later respawn. Following this example It works very well for me and is able to do what I need.

There are heaps of different implementations of FArchive and it totally depends on your context. The following though may be want you want. It converts any objects (including classes) and FNames to FString, then passes that to the archive that it’s wrapping. It obviously only works on objects that have a fixed path, but in the case of classes that’s always the case.

#include "Serialization/ObjectAndNameAsStringProxyArchive.h"

FBufferArchive Ar;
FObjectAndNameAsStringProxyArchive WrappedAr(Ar, true);
WrappedAr << MyClass;

How can i convert a class to an int?