I am trying to create a static mesh component under a subclass of PrimitiveComponent. I create it using CreateDefaultSubObject and attach it using AttachParent in the constructor of the primitive component class:
UExtendedPrimitiveComponent::UExtendedPrimitiveComponent(const FObjectInitializer& ObjectInitializer)
MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComponent"));
MeshComponent->AttachParent = this;
Next, I add extended primitive component to an actor, which is also blueprintable but in blueprint editor, I don’t see the static mesh in viewport after I set the static mesh of the static mesh component in defaults panel.
Am I missing something between the lines?
I am not certain about this and it’s just my best guess, but in blueprint at least components don’t have subcomponents, despite them appearing in the actor hierarchy in a way that looks like that. Afaik the actor is the thing that stores the entire hierarchy of the components, and nothing actually looks into the components themselves. I think you should still be able to access the meshcomponent through code as you’d expect, but it will probably act funky since it’s not attached to the actor the way you’d expect.
What I’ve done in the past for “components” that need their own component hierarchies is make the component an actor and then put that actor into a childactorcomponent, which you unfortunately also can’t really edit in the editor defaults.
Depending what you want, there are ways around it, but I don’t think there’s a good way to get exactly what you want
Ok then, I will have to develop my own workaround. Thanks for your help, you saved me a lot of time.