Search Unity

Order of materials in mesh renderer array is seamingly random

Discussion in 'Asset Importing & Exporting' started by Gaaius, Dec 13, 2020.

  1. Gaaius

    Gaaius

    Joined:
    Nov 3, 2020
    Posts:
    1
    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. buu.png
     
  2. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    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.
     
    Sluggy, OzgurGurbuz, avidpl and 7 others like this.
  3. BronsonBrad

    BronsonBrad

    Joined:
    Jan 6, 2013
    Posts:
    8
    Thanks Siccity! Just what I was after.
     
  4. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    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
     
    Balours and Siccity like this.
  5. Docboy

    Docboy

    Joined:
    Sep 11, 2013
    Posts:
    14

    Perfectly applied, thanks
     
  6. jimmying

    jimmying

    Joined:
    Sep 20, 2017
    Posts:
    107
    If this doesn't work for anyone else, try using faces rather than vertices -- that's what worked for me.
     
    Sluggy, RoyBarina and homemacai like this.
  7. ngduykhanh

    ngduykhanh

    Joined:
    Mar 14, 2018
    Posts:
    5
    Thank you!!!
     
  8. tannern

    tannern

    Joined:
    May 14, 2013
    Posts:
    1
    Thank you!
     
  9. esgnn

    esgnn

    Joined:
    Mar 3, 2020
    Posts:
    38
    Vagabond_ likes this.
  10. Juaninside

    Juaninside

    Joined:
    Oct 30, 2014
    Posts:
    6