To be frank I'm not 100% sure if the problem I have is with Blender 3.0's FBX export or Unity 2020's FBX import, but that said maybe someone who knows more about this can help.
I have some scripting in Unity that dynamically modifies the first material on a MeshRenderer, and leaves the other materials, if any, alone. The idea is that the first material should be set by the artist as the "main" material, typically white, and the script can modify aspects such as HSV to give a visual effect.
Each material is applied to a distinct subset of faces of course.
The problem is that for some of the models I FBX-export from Blender, the first material slot shown in Unity (as an array of Materials) is not the first one that was defined in Blender. For example, Blender might show the following material slots with useful material names:
- White
- Grey
- Black
But after import the resultant FBX into Unity, the material array in the MeshRenderer shows in this order:
- Grey
- White
- Black
Grey and White have switched places. This means that the script operates on the Grey faces, not the White ones as intended. Reordering the elements of the MeshRenderer's array just applies the wrong materials to the wrong sets of faces, it doesn't change which set of faces is considered the assignment for the "first" material.
Changing the order of material slots in Blender seems to have no effect. I've also tried temporarily reassigning each set of faces to temporary materials, creating new materials in the correct slots, and assigning the faces back, but this doesn't seem to solve this problem either.
I've seen some historical comments from Blender developers along the lines of "material slots order doesn't matter" but I wonder if this is one situation where it might?
Or is there a better way to do this? Is there a convention for assigning metadata within an FBX to indicate to something like Unity which material is which? The script could search for a material name like "White" or "Main" but that seems to overload the purpose of the name somewhat.
(Is there a good FBX viewer that allows me to see the deserialised data within the binary FBX, so that I can see if changing anything in Blender actually changes anything with the serialisation order - that would help me work out if it's Blender's export or Unity's import that is the source of this issue).