Material Reference Animation referencing the wrong Material?

I’m working on an Avatar 3.0 character with several customizable materials. To do this, I’ve added an animation which swaps the material for each clothing item, and you can swap the materials with the expressions menu.

For each material, this works, except for material slot 2. In the Unity editor, it looks fine:

But in the game, it applies the material to material slot 4.
image_2020-11-04_054046

Googling this, it seems to be a known issue with Unity. Is there any way around this?

Bumping this with my own workaround so future generations will know. If you go into Blender, change the material order in the materials panel, select all your faces in edit mode, and hit Mesh > Sort Elements… > Material, you can just rearrange the order of materials in your object.

I just switched Material 2 with Material 0, since I was never going to change Material 2 anyway.
image
image

This will change the order of materials in Unity.
image

Then, to change each animation quickly, I started a Powershell prompt in my game assets folder and did this in the folder with my shirt animations:

gci -r -include "*.anim" |
 foreach-object { $a = $_.fullname; ( get-content $a ) |
 foreach-object { $_.Replace("m_Materials.Array.data[2]", "m_Materials.Array.data[0]") }  | 
set-content $a }

Source for this script.

It works fine now.
image

I would recommend for future reference just removing any underscores and parenthesis from the Material names. Sometimes assignment gets a little wonky in Unity/C# and breaks the arrays.

Good to know. I wasn’t aware of that, especially since the material combiner in Cats’s Blender plugin makes atlases with underscores in the name. I’ll be sure to scrub special characters from my materials in the future.