Download

Prevent UProceduralMeshComponent from being serialized?

I have a bunch of runtime generated meshes that use UProceduralMeshComponent, and one minor thing I noticed was that the mesh data was being saved as part of the .umap file, unnecessarily (in my case) bloating the file size from a few kb to several megabytes.

I have a fix of sorts that when it detects that the file is about to be saved, it clears the mesh data and signals the owning actor that the mesh will need to be rebuilt from scratch.


void UMyProceduralMeshComponent::Serialize( FArchive & a ) {

	//dlogf( "UMyProceduralMeshComponent::Serialize save=%d load=%d", a.IsSaving(), a.IsLoading() );
	//dprintfScope();

	if ( a.IsSaving() && GetNumSections() > 0 && !a.IsTransacting() ) {
		dlogf( "UMyProceduralMeshComponent::Serialize - erase mesh data before serializing, save .umap file size" );
		dprintfScope();
		// weird hack, remove all mesh data if saving
		ClearAllMeshSections();
		ClearCollisionConvexMeshes();
		if ( MarkForBuild ) {
			MarkForBuild();
		}
	}

	Super::Serialize( a );

}


Question is, without wiping out the mesh data, is there an easy way to prevent the component or it’s mesh data from being serialized into the .umap or .uasset?

Thanks!

IIRC the property specifier “Transient” will keep it from being serialized. Property Specifiers | Unreal Engine Documentation