@@ -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>
@@ -610,6 +621,25 @@ protected bool ExportInstance (GameObject unityGo, FbxNode fbxNode, FbxScene fbx
610
621
return true ;
611
622
}
612
623
624
+ /// <summary>
625
+ /// Ensures that the inputted name is unique.
626
+ /// If a duplicate name is found, then it is incremented.
627
+ /// e.g. Sphere becomes Sphere_1
628
+ /// </summary>
629
+ /// <returns>Unique name</returns>
630
+ /// <param name="name">Name</param>
631
+ private string GetUniqueName ( string name )
632
+ {
633
+ var uniqueName = name ;
634
+ if ( NameToIndexMap . ContainsKey ( name ) ) {
635
+ uniqueName = string . Format ( UniqueNameFormat , name , NameToIndexMap [ name ] ) ;
636
+ NameToIndexMap [ name ] ++ ;
637
+ } else {
638
+ NameToIndexMap [ name ] = 1 ;
639
+ }
640
+ return uniqueName ;
641
+ }
642
+
613
643
/// <summary>
614
644
/// Unconditionally export components on this game object
615
645
/// </summary>
@@ -625,7 +655,7 @@ protected int ExportComponents (
625
655
}
626
656
627
657
// create an FbxNode and add it as a child of parent
628
- FbxNode fbxNode = FbxNode . Create ( fbxScene , unityGo . name ) ;
658
+ FbxNode fbxNode = FbxNode . Create ( fbxScene , GetUniqueName ( unityGo . name ) ) ;
629
659
NumNodes ++ ;
630
660
631
661
numObjectsExported ++ ;
0 commit comments