When instantiating a static mesh object from c++ code, setting it attached to a RootComponent causing it to become “invisible” in the scene during the runtime. Though, it still calculates the collision.
Sample code:
// Box for overlap listener
BaseCollisionComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("BaseCollisionBox"));
// Set root component to be a collision box
RootComponent = BaseCollisionComponent;
WeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMesh"));
//WeaponMesh->SetupAttachment(RootComponent); // Makes it disappear on runtime.
WeaponMesh->RelativeRotation = FRotator(0.0f, 0.0f, 0.0f);
WeaponMesh->RelativeLocation = FVector(0.0f, 0.0f, 0.0f);
Commenting out this line
WeaponMesh->SetupAttachment(RootComponent);
Makes it behave as expected (visible in the scene and life is good).
Why is that happening and what am I doing wrong here?
And do I “need” to make it attached to RootComponent in a first place?
Side note:
I check “visible” and “hidden in game” flags for both RootComponent and StaticMesh.
Tried adjusting “bounds scale” value (haven’t yet understood the purpose of this).
Searched for the answer on the forums, but haven’t found an explanation for this.
Thanks.