how does the mesh filter chose which material to use in a multiple material 3d model?

The Problem
I am working on a tile-based project and I need to switch the mesh filter of tile at runtime. On this tile object, I have two materials, one top material, and base material.
But when I change the mesh filter of a tile(to have a different look to the tile), it swaps the two materials of the 3d model. Some types of tiles that I swap are fine and have the correct material assigned to the specific faces, but most of the materials are inverted.

Things that I tried
So I tried to see if this has to do with the order of the materials in my 3d software blender, but the order did not do anything to fix the problem. I tried to invert the two materials in blender, but this also did nothing. Only if I assign a different face to a material I will see a difference in the model. And if I try to do this face by face to make the material not inverted, it will eventually switch back to the incorrect material placement. Overall, I just keep getting inconsistent errors and I don’t know what to do to debug this.

My guess is that unity makes the order differs depending on the number of faces that a particular material has(and that has to do with the mesh filter). Or I am using blender incorrectly and have some sort of bug with the model.

here’s some screenshot to better visualize my problem :

conclusion
If anyone has any insight on how I can fix this problem it would be most appreciated. I would like to know more about mesh filters if possible, the unity documentation doesn’t provide the information that I need to solve this. it would be nice to know how does the mesh filter chose the material if they are multiple ones for example.

ok, it’s with the indices of the vertex that unity is used to determine which material goes first in the mesh rendered. in blender there’s a button that rearrange the indices so that it will always show the desired material first