Cooking UInstancedStaticMeshComponent Created at Runtime

Running into a slight problem when cooking an instance of an actor that contains UInstancedStaticMeshComponent that was created in OnConstruction. The cook always crashes at line 1595 of InstancedStaticMesh.cpp with means my PerInstanceRenderData isn’t valid.

The creation of the component itself looks like this.

InstancedStaticMeshComponent = NewObject<UInstancedStaticMeshComponent>(this);
InstancedStaticMeshComponent->SetFlags(RF_Public | RF_Standalone);
InstancedStaticMeshComponent->RegisterComponent();
InstancedStaticMeshComponent->SetStaticMesh(StaticMeshParameter.StaticMesh);
InstancedStaticMeshComponent->SetCollisionProfileName(TEXT("WorldStatic"));
InstancedStaticMeshComponent->SetMobility(EComponentMobility::Static);
InstancedStaticMeshComponent->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::SnapToTargetIncludingScale);

The StaticMesh comes from a struct which contains a bunch of options for which mesh to display, and any transformation randomization that may happen on that static mesh instance.
I’ve tried various flags in the SetFlags function thinking that was perhaps my problem to no avail.

Solved my own problem. Code below for anyone who runs into the same thing.

InstancedStaticMeshComponent = NewObject<UInstancedStaticMeshComponent>(this, NAME_None, RF_NeedPostLoad);
InstancedStaticMeshComponent->SetStaticMesh(StaticMeshParameter.StaticMesh);
InstancedStaticMeshComponent->SetCollisionProfileName(TEXT("WorldStatic"));
InstancedStaticMeshComponent->SetMobility(EComponentMobility::Static);
InstancedStaticMeshComponent->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::SnapToTargetIncludingScale);
InstancedStaticMeshComponent->RegisterComponent();
InstancedStaticMeshComponent->ConditionalPostLoad();