Download

Creating an editable component hierarchy in C++

My current task is to import a 3rd party compound mesh file format which is basically a list of static mesh names and transforms. To do this, I’ve create an actor subclass AMultiMesh which has a single USceneComponent, SceneRoot. To that, I load the parts as UStaticMesh and attach:



auto * partMesh = Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), nullptr, *ue4path));
if (!partMesh)
{
    const auto message = FString::Printf(TEXT("Could not locate sub-object '%s'"), *ue4path);
    UE_LOG(LogTemp, Error, TEXT("%s"), *message);
    log.Error(FText::FromString(message));
    continue;
}

auto * const component = NewObject<UStaticMeshComponent>(rootActor);
if (IsValid(component))
{
    component->SetStaticMesh(partMesh);
    component->SetupAttachment(rootActor->SceneRoot);
    component->SetRelativeTransform(partTransform);
    component->RegisterComponent();
}
else
{
    const auto message = FString::Printf(TEXT("Could not create part: '%s'"), *ue4path);
    UE_LOG(LogTemp, Error, TEXT("%s"), *message);
}



This works well, however the hierarchy is not editable:

hierarchy.png
The SceneRoot doesn’t show the meshes added (though they’re clearly visible in the viewport).

I’d like to see a list of the added meshes under SceneRoot and be able to tweak their transforms etc, but can’t see a straightforward way to do this for a variable number of child meshes.