CreateDefaultSubobject inside child component attached to an actor loses values in blueprint editor

I have the following actor:


 UCLASS()
class X_API AMoveableRigidBodyActor : public AActor
{
   GENERATED_BODY()

public:

   // Sets default values for this actor's properties
   AMoveableRigidBodyActor();

public:

UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Custom")
   USceneComponent* SceneComponent;

UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Custom")
    UMoveableRigidBodyComponent* MoveableRigidBodyComponent;

};
  

This Actor makes a reference to a UMoveableRigidBodyComponent and a USceneComponent which I run CreateDefaultSubobject on and attach in the following fashion in the constructor:


 AMoveableRigidBodyActor::AMoveableRigidBodyActor()
{

   SceneComponent = CreateDefaultSubobject<USceneComponent>(FName("AMoveableRigidBodyActor_SceneComponent"));
   SetRootComponent(SceneComponent);

   MoveableRigidBodyComponent = CreateDefaultSubobject<UMoveableRigidBodyComponent>(FName("AMoveableRigidBodyActor_MoveableRigidBodyComponent"));
   MoveableRigidBodyComponent->SetupAttachment(SceneComponent);

}
  

So far, so good.

Now inside my UMoveableRigidBodyComponent I instantiate a few components that are relevant to that component. I expect these components to be visible and manageable from within my blueprint:


 UCLASS()
class X_API UMoveableRigidBodyComponent : public USceneComponent
{
   GENERATED_BODY()

public:

   // Sets default values for this component's properties
   UMoveableRigidBodyComponent();

override;

UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Custom")
   USceneComponent* SceneComponent;

UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Custom")
   UStaticMeshComponent* StaticMeshComponent;

};
  

Here I use CreateDefaultSuboject to attach everything to this component:


 UMoveableRigidBodyComponent::UMoveableRigidBodyComponent()
{
   SceneComponent = CreateDefaultSubobject<USceneComponent>(FName("UMoveableRigidBodyComponent_SceneComponent"));
   SceneComponent->SetupAttachment(this);

   StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(FName("UMoveableRigidBodyComponent_StaticMeshComponent"));
   StaticMeshComponent->SetupAttachment(SceneComponent);
}
  

So, all of this feels pretty normal so far. So I go into my editor, create a blueprint that’s based off of the AMoveableRigidBodyActor and I assign a static mesh to my component:

c681300d2aa5d6d486ee1392c6943819fdf54c24.jpeg
https://forums.unrealengine.com/core/image/gif;base64

Still good. But then I hit the compile button:

67acb4944889132a8c28b1909154956a5ac8a458.jpeg
https://forums.unrealengine.com/core/image/gif;base64

The selected static mesh has now vanished from the editor but still seems to be filling the value correctly.

Furthermore, if I put this into the game world you can see that the static mesh sure enough isn’t there in the instance:

553fa3868fb577ec536f6447588ccdd6588eaca4.jpeg
https://forums.unrealengine.com/core/image/gif;base64

What am I misunderstanding here?

Anything I can do here to help you answer my question. I’m still stuck :slight_smile:

Any thoughts?