UStaticMeshComponent invisible in game

Hello, I am trying to redo an entire BP into C++ to create a more versatile Master class. However I have run into a problem. I have been able to redo everything but the components of the BP and at the moment I am struggling with getting the static mesh to work at all. I have created a simple static mesh component like this: (It’s being inherited but I have editable when inherited enabled) if that matters.

UPROPERTY(BlueprintReadWrite, EditAnywhere)
		UStaticMeshComponent* StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Static Mesh"));

Then I have replaced every time the editor made static mesh was used with my c++ made one but the static mesh wont even show up in the game. Am I missing something fundamentally or is the problem something non code related?

Hey, initialisation should be done in the constructor.

so keep this :
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UStaticMeshComponent* StaticMesh;

and add this :

AMyClass::AMyClass()
{
StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Static Mesh"));
}

and with a rebuild you should be good :slight_smile:

It’s still not working, and with a close look I can see that my “Set Static Mesh” node returns false despite the “New Mesh” input having a valid static mesh as it’s value. And the Static Mesh Component does have mobility movable so it isn’t that.

There was apparently a transform problem causing me to not see the static mesh. Thanks for the quick answer but why aren’t static meshes bound to their root the same way as if they were made in BP’s? I have attached it to a Scene Component and keept it’s transform rule relative