How to add components to "components" tab from code

Hi guys,

probably a basic question, but how can I add components to “components” tab from code? (‘Components’ tab is visible when You open blueprint in question).

I have base class and i want to all my derived blueprints have static mesh component in their components tab. Now i have something like this:

    m_StaticMeshComp = NewObject<UStaticMeshComponent>(this, UStaticMeshComponent::StaticClass(), FName("my static mesh comp"));
    check(m_StaticMeshComp);
    m_StaticMeshComp->RegisterComponent();
    m_StaticMeshComp->AttachTo(GetRootComponent());

but this adds component to “details” tab instead of “components”.

Thanks in advance :slight_smile:

In your constructor create the component using the ObjectInitializer.
Syntax:

// in header
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Mesh)
class UStaticMeshComponent* MyNativeComponentPtr ;

//in constructor
MyNativeComponentPtr = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, MyStaticMeshComponentName);

Hi,

great it works. It turns out that this magic ObjectInitializer is actually usuful for something. Official documentation mentions something about it but i really don’t understand it much. Maybe You can give some insights about this object? What the hell it is doing etc?

cheers