Ok so, I have an Object of MechPart, that extends AActor. It has a static mesh component that I set as it’s RootComponent, which would be things like weapons/Armour:
meshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MechAttachment_MeshComponent"));
SetRootComponent(meshComponent);
Once I set the owner of a MechPart in the world, I attach it to a socket on my character called RightHand:
void AMechPart::SetOwner(AMech_RPGCharacter* inOwner)
{
Super::SetOwner(inOwner);
if (mesh == nullptr && meshClass != nullptr) {
mesh = GetWorld()->SpawnActor<UStaticMesh>(meshClass);
}
if (mesh != nullptr) {
meshComponent->SetStaticMesh(mesh);
//meshComponent->SetMobility(EComponentMobility::Movable);
/*meshComponent->bOwnerNoSee = false;
meshComponent->bCastDynamicShadow = true
meshComponent->CastShadow = true;*/
meshComponent->SetHiddenInGame(false);
meshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
if (inOwner != nullptr && inOwner->GetMesh() != nullptr) {
AttachRootComponentTo(inOwner->GetMesh(), "RightHand");
}
}
}
Up till this point everything is fine. It gets created and locks into position on my characters.
When I try SetActorHiddenInGame(), the mesh of the component, is still shown. So I tried to override this by doing this:
void AMechPart::SetActorHiddenInGame(bool bNewHidden)
{
Super::SetActorHiddenInGame(bNewHidden);
GetRootComponent()->SetHiddenInGame(bNewHidden, true);
meshComponent->SetHiddenInGame(bNewHidden, true);
meshComponent->SetVisibility(!bNewHidden, true);
}
But nothing changed, the StaticMesh is still being shown within the level. It even persists if I call Destroy() on MechPart.
Does anyone have any idea why? I’m not 100% sure if I need to manually destroy the MeshComponent itself, as it is part of MechPart and Destroy() works with everything else I do it to, ther characters for isntance.