@@ -69,6 +69,17 @@ public static ModelExporter Create ()
69
69
/// </summary>
70
70
Dictionary < string , FbxMesh > SharedMeshes = new Dictionary < string , FbxMesh > ( ) ;
71
71
72
+ /// <summary>
73
+ /// Map for the Name of an Object to number of objects with this name.
74
+ /// Used for enforcing unique names on export.
75
+ /// </summary>
76
+ Dictionary < string , int > NameToIndexMap = new Dictionary < string , int > ( ) ;
77
+
78
+ /// <summary>
79
+ /// Format for creating unique names
80
+ /// </summary>
81
+ const string UniqueNameFormat = "{0}_{1}" ;
82
+
72
83
/// <summary>
73
84
/// return layer for mesh
74
85
/// </summary>
@@ -587,6 +598,25 @@ protected bool ExportInstance (GameObject unityGo, FbxNode fbxNode, FbxScene fbx
587
598
return true ;
588
599
}
589
600
601
+ /// <summary>
602
+ /// Ensures that the inputted name is unique.
603
+ /// If a duplicate name is found, then it is incremented.
604
+ /// e.g. Sphere becomes Sphere 1
605
+ /// </summary>
606
+ /// <returns>Unique name</returns>
607
+ /// <param name="name">Name</param>
608
+ private string GetUniqueName ( string name )
609
+ {
610
+ var uniqueName = name ;
611
+ if ( NameToIndexMap . ContainsKey ( name ) ) {
612
+ uniqueName = string . Format ( UniqueNameFormat , name , NameToIndexMap [ name ] ) ;
613
+ NameToIndexMap [ name ] ++ ;
614
+ } else {
615
+ NameToIndexMap [ name ] = 1 ;
616
+ }
617
+ return uniqueName ;
618
+ }
619
+
590
620
/// <summary>
591
621
/// Unconditionally export components on this game object
592
622
/// </summary>
@@ -602,7 +632,7 @@ protected int ExportComponents (
602
632
}
603
633
604
634
// create an FbxNode and add it as a child of parent
605
- FbxNode fbxNode = FbxNode . Create ( fbxScene , unityGo . name ) ;
635
+ FbxNode fbxNode = FbxNode . Create ( fbxScene , GetUniqueName ( unityGo . name ) ) ;
606
636
NumNodes ++ ;
607
637
608
638
numObjectsExported ++ ;
0 commit comments