@@ -135,6 +135,12 @@ public static GameObject Convert (
135
135
}
136
136
var projectRelativePath = EditorTools . ExportSettings . GetProjectRelativePath ( fbxFullPath ) ;
137
137
138
+ // Make sure that the object names in the hierarchy are unique.
139
+ // The import back in to Unity would do this automatically but
140
+ // we prefer to control it so that the Maya artist can see the
141
+ // same names as exist in Unity.
142
+ EnforceUniqueNames ( new GameObject [ ] { toConvert } ) ;
143
+
138
144
// Export to FBX. It refreshes the database.
139
145
{
140
146
var fbxActualPath = ModelExporter . ExportObject (
@@ -268,6 +274,40 @@ public static string IncrementFileName(string path, string filename)
268
274
return file ;
269
275
}
270
276
277
+ /// <summary>
278
+ /// Enforces that all object names be unique before exporting.
279
+ /// If an object with a duplicate name is found, then it is incremented.
280
+ /// e.g. Sphere becomes Sphere 1
281
+ /// </summary>
282
+ /// <param name="exportSet">Export set.</param>
283
+ public static void EnforceUniqueNames ( IEnumerable < GameObject > exportSet )
284
+ {
285
+ Dictionary < string , int > NameToIndexMap = new Dictionary < string , int > ( ) ;
286
+ string format = "{0} {1}" ;
287
+
288
+ Queue < GameObject > queue = new Queue < GameObject > ( exportSet ) ;
289
+
290
+ while ( queue . Count > 0 )
291
+ {
292
+ var go = queue . Dequeue ( ) ;
293
+ var name = go . name ;
294
+ if ( NameToIndexMap . ContainsKey ( name ) )
295
+ {
296
+ go . name = string . Format ( format , name , NameToIndexMap [ name ] ) ;
297
+ NameToIndexMap [ name ] ++ ;
298
+ }
299
+ else
300
+ {
301
+ NameToIndexMap [ name ] = 1 ;
302
+ }
303
+
304
+ foreach ( Transform child in go . transform )
305
+ {
306
+ queue . Enqueue ( child . gameObject ) ;
307
+ }
308
+ }
309
+ }
310
+
271
311
/// <summary>
272
312
/// Updates the meshes and materials of the exported GameObjects
273
313
/// to link to those imported from the FBX.
0 commit comments