Why is Unity renaming my meshes?

What I have is a piece of equipment that has all it’s parts (buttons, switches, etc) broken out into individual meshes. They are all parented so that no meshes with the same name exist under the same parent, but I have things like:
…rootmesh
…card1
…switch1
…switch2
…card2
…switch1
…switch2

I export an FBX and bring it into Unity, but as soon as I put it in the scene it’s appending numbers to the duplicate names like:
…rootmesh
…card1
…switch1 1
…switch2 1
…card2
…switch1 2
…switch2 2

Has anyone else seen this and is there a workaround other than forcing unique names from the source mesh file? Thanks.

FBX doesn’t like duplicate names.

That would make sense if the FBX exporter complained when trying to export, but it doesn’t (at least not when they’re in different parts of the hierarchy, even Maya will not allow the same name to be duplicated by different meshes under the same parent, though 3DSMax doesn’t care). Also, if I open the source mesh tree in Unity I see all the original names. So it’s only when the mesh is put into a prefab or dragged directly into the Scene View that the numbers are appended to the ends of the similar names. If there’s no other way around this I guess we’ll have to make a script that removes these numbers from the prefab suffix.

As an additional test, since 3DSMax doesn’t care about duplicate names I created a “rootmesh” object with two children both named “sphere01”. When exported to FBX there were no warnings or errors. However, when Unity imported the FBX there was a difference… in the source mesh tree they had been renamed to “sphere01” and “sphere01 1”. As I mentioned before though, when the identical names don’t exist at the same hierarchy level (different parents) they come into Unity with their same original names in the source mesh tree, and it’s only when placed into a prefab or the scene that they’re renamed.

I am having this same issue and it is driving me crazy. I will be writing a script today to handle this problem but I am not at all happy about it. Why there is no control over the engine renaming objects is beyond me.

I wrote a dandy little script that extends the editor and has a simple button that locates all the numbered objects and removes the appended numbers. Check it out:

// This script renames all the objects in the scene that have a number appended to it by the Unity importer
// It searches for game objects that contain a space character in them and then truncates the string at the space
// PLEASE NOTE: You MUST ensure that none of your other game objects use spaces, otherwise this will truncate them too


class ObjectRenamer extends EditorWindow {
    
    // Add menu named "ObjectRenamer" to the Window menu
    @MenuItem ("Window/ObjectRenamer")
    static function Init () {
        // Get existing open window or if none, make a new one:
        var window : ObjectRenamer = EditorWindow.GetWindow (ObjectRenamer);
    }
    
    function OnGUI ()
	{
		// Label/Instructions
		GUILayout.Label ("Click Button To Remove All Numbers", EditorStyles.boldLabel);
		
		// Place all GameObjects into a variable
		var obj : Object[] = GameObject.FindObjectsOfType(typeof (GameObject));
		
		// Draw Button and do on click
		if (GUI.Button(Rect(10,70,100,30),"Run Script"))
		{
			// Start a for loop that runs through all game objects
			for (var o : GameObject in obj)
			{
				// If the game object's name has a space in it...
				if (o.name.IndexOf(" ") != -1)
				{
					// Truncate the game object's name just before the space by locating where in the string the space is located
					o.name = o.name.Substring(0,(o.name.IndexOf(" ")));
				}
			}
		}
    }
}

Just put the script in folder named “Editor” within your “Assets” folder. Then go into the editor, select Window from the toolbar, and then you should see “ObjectRenamer” in your list.

1 Like

This is still causing problems in 2017, over half a decade later. I wrote a script that matched up two trees of objects by name, which worked fine until I tried to use it on an imported FBX and found how it unnecessarily renames things.