Hello everyone.
I am trying to add static mesh components to my own Actor-derived class during construction:
void AMyActor::OnConstruction(const FTransform& Transform)
{
UStaticMeshComponent* meshComponent = ConstructObject<UStaticMeshComponent>(UStaticMeshComponent::StaticClass(), this);
meshComponent->CreationMethod = EComponentCreationMethod::UserConstructionScript;
meshComponent->AttachTo(GetRootComponent());
meshComponent->RegisterComponent();
}
This really works fine as long as I am in editor mode. I can see the component in hierarchy view. But when switching to play mode the constructed static mesh component won’t show up. The only persistent component is the root scene node which was added in the constructor of my class:
SetRootComponent(ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, "MyRootNode"));
What am I missing? I am using Version 4.7.6.
Thanks for your help!