Order of materials in mesh renderer array is seamingly random

I have three objects (meshes) in blender, each with the same three materials.

They have the same order in blender, but in Unity the materials in the mesh renderer are in random order. This is bad if i want to change one of the materials, because then different parts of the meshes get the new material.

In the Image you can see excerpts from the mesh renderer og each mesh, the materials for the meshes in blender and what happens if i assign a Material to element 0, 1 and 2 of all objects simultaniously (Left from blender and right in Unity in similar colours) ( i know that thats not supposed to work, given the different orders)

How do i ensure, that all the objects retain the order of the materials from Blender?
I import the .blend file to unity.

It’s been a long time since I had this problem myself, but iirc Unity orders the materials based on vertex order.
To fix this in blender, select all your vertices in edit mode, and hit Mesh > Sort Elements > Material.

14 Likes

Thanks Siccity! Just what I was after.

I wish this worked for me … Blender 2.9 … in the end I noticed that the FBX materials are sorted by alphabet… so I fixed the material ordering by using numbers

  • 0_materialA
  • 1_materialB
  • etc
  • etc
2 Likes

Perfectly applied, thanks

If this doesn’t work for anyone else, try using faces rather than vertices – that’s what worked for me.

6 Likes

Thank you!!!

Thank you!

What worked for me was separating by material and re-joining them before exporting
https://blender.stackexchange.com/questions/249238/how-to-control-material-slot-order-in-fbx-export

2 Likes

This worked for me!, the sorting thingy didn’t working at all but this fixed the issue, thank you very much! :slight_smile:
Note: I was using Blender 3.6 and Unity 2023.1.13f1