Spawning a StaticMeshComponent

Hi,

I need to create a StaticMeshComponent in real time. I don’t want to declare it as a component inside the header file because I will have a few instances of this, so I took a look at the LoadObject method but I can’t get it to work. I did this :

UStaticMesh * StaticMesh = LoadObject<UStaticMesh>(NULL, TEXT("/Game/PathToMyMesh"), NULL, LOAD_None, NULL);
UStaticMeshComponent* Test = ConstructObject<UStaticMeshComponent>(UStaticMeshComponent::StaticClass());
Test ->SetStaticMesh(StaticMesh);
Test ->AttachTo(RootComponent);

Unfortunately I can see no trace of the mesh inside the game. Is this the right way to do it ?

The “Test” component is correctly initialized when I take a look in the debugger, it is just invisible.

Okay, I just needed to register the component.

UStaticMesh* StaticMesh = LoadObject<UStaticMesh>(NULL, TEXT("..."), NULL, LOAD_None, NULL);
UStaticMeshComponent* Test = ConstructObject<UStaticMeshComponent>(UStaticMeshComponent::StaticClass(), xxxx);
Test->SetStaticMesh(StaticMesh);
Test->SetWorldLocation(GetComponentLocation());
Test->RegisterComponentWithWorld(xxxx->GetWorld());
Test->AttachTo(xxxx);