Attaching StaticMeshComponent to another Component - Mesh not visible?

I have a component which is dynamically spawned during the game and attached to a pawn (UMiningComponent). That part works fine. However what i’m trying to do is to then add an another component with a mesh to it (Component B). Unfortunately when I do this the mesh isn’t visible. Can someone see what I’m doing wrong?

.h



class SPACECOOP_API UMiningComponent : public UStaticMeshComponent
{
	GENERATED_BODY()

	UMiningComponent(const FObjectInitializer& ObjectInitializer);
	

public:
	/** Static Mesh*/
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Custom)
	UStaticMeshComponent* MiningActiveMesh;

	
};

.cpp



UMiningComponent::UMiningComponent(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{

	MiningActiveMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("MiningMesh"));
	MiningActiveMesh->AttachTo(this);
	MiningActiveMesh->bVisible = true;

}


Hello, UStaticMeshComp don’t have a mesh by default, so you need to set one : MiningActiveMesh->SetStaticMesh(UStaticMesh*); Or you can set it inside the editor since you set it to be visible for the editor.

Hi ,

I’ve set up a blueprint and assigned a mesh to it there. If I manually attach the component then I can see that it has the StaticMeshComponent present, and that there is a mesh assigned to it. However the mesh isn’t visible in the editor or game.

Well i don’t know but it might be that you don’t set the root component : RootComponent = MiningActiveMesh; use this instead of attachto(this).