Hi!
I’m using the USD Importer to import files into my level. However, the actors created do not respect Unreal’s naming convention.
For example, if I imported such a file :
USD file example (assume it works and is correct)
#usda 1.0
def "Scene"
{
def Xform "Component1"
{
def Mesh "Cube"
{}
}
def Xform "Component2"
{
def Mesh "Cube"
{}
}
}
The resulting actor would be :
Actor (with the autogenerated suffixes)
Actor
> Scene_0 (RootComponent)
> Component1_0
> Cube_0
> Component2_1
> Cube_0
So I tried dealing with this in C++ like this :
// Check for duplicate names
bool bAllUnique = true;
TArray<FString> Names;
for (auto Comp : Actor->GetComponents()) {
if (Names.Contains(Comp->GetName())) {
bAllUnique = false;
break;
}
Names.Add(Comp->GetName());
}
if (!bAllUnique) {
for (auto Component : Actor->GetComponents()) {
// Try removing the suffix first
FString NameNoSuffix = RemoveSuffix(Component->GetName());
bool bRenameSucess = Component->Rename(*NameNoSuffix);
int32 I = 0;
while (!bRenameSucess) {
// If removing the suffix wasn't enough, add a new suffix until it works
FString NewName(NameNoSuffix + "_" + FString::FromInt(I++));
bRenameSucess = Component->Rename(*NewName);
}
}
}
This issue is that I end up with only the suffixes removed (Rename doesn’t fail even though a component already has the name).
How can I make sure the components have unique names, while being as close as possible to the USD names?