Transient component is still saved/loaded

I’ve got following code in my actor

// header
...
#if WITH_EDITOR
	UPROPERTY(Transient)
	class UProceduralMeshComponent* ProceduralMesh;
#endif
...
// cpp, constructor
...
#if WITH_EDITOR
	static ConstructorHelpers::FObjectFinder<UMaterial> GridMaterial(TEXT("Material'/Game/Common/M_PathGrid.M_PathGrid'"));
	ProceduralMesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("GeneratedMesh"), true); // Notice true as second parameter
	ProceduralMesh->SetMaterial(0, GridMaterial.Object);
	ProceduralMesh->SetupAttachment(RootComponent);
#endif
...

The intention is simple: I don’t want this component to be saved or loaded to disk since it contains large mesh and should only be avaialble in editor. It’s used for debugging purposes only.

However it’s still saved when I press save and loaded when I open level after editor restart. Also tried SkipSerialization, didn’t help. And I see this component when I select the actor in the editor.

How can I totally exclude component from being serialized? I will always generate its content on the fly when necessary.

Did you ever figure this out?

This is how the engine does it:

    #if WITH_EDITOR && WITH_EDITORONLY_DATA
ProcMesh = CreateEditorOnlyDefaultSubobject<UProceduralMeshComponent>(TEXT("GenMesh"));
    #endif

Put this in the constructor, no need to put the property Transient, it wont exist out of the editor.

AFAIR, no. I just dropped this code.

This is how you mark a component as transient, it will not be saved into the level:

ProceduralMesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("GeneratedMesh"));
ProceduralMesh->SetFlags(EObjectFlags::RF_Transient);

What is the difference between EObjectFlags::RF_Transient and UPROPERTY(Transient)?

EObjectFlags::RF_Transient makes it so that the object doesn’t get saved into the level.
UPROPERTY(Transient) makes it so that the property never gets serialized or saved.

1 Like