# Multi Material ID

**URL:** <https://discussions.unity.com/t/multi-material-id/395852>\
**Category:** Shaders & Materials\
**Created:** [August 3, 2009, 12:09pm UTC](https://discussions.unity.com/t/multi-material-id/395852 "2009-08-03T12:09:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon\_28146080](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@anon\_28146080](https://discussions.unity.com/u/anon_28146080)\
**Post date:** [August 3, 2009, 12:09pm UTC](https://discussions.unity.com/t/multi-material-id/395852/1 "2009-08-03T12:09:42Z")

</div>

Hi,  
I’m trying to work with a mesh with a multi material.  
I’ve a set of models with 4 ID each  
1234  
and 4 relative materials in Unity to assign  
1234

**When I import the FBX (from Max), Unity assigns random materials only on some meshes.** The courious fact is that they are all the same.  
mesh1, ID 1234, Mat 1234  
mesh2, ID 1234, Mat 1423  
and so on…

The question is: **is there a way to fix the Mat ID order of imported meshes manually?** Because with Drag&Drop Unity does a mess swapping materials (again randomly).

Thanks!

---

<div class="post-metadata">

**Author:** ![anon\_88649125](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@anon\_88649125](https://discussions.unity.com/u/anon_88649125)\
**Post date:** [August 3, 2009, 7:52pm UTC](https://discussions.unity.com/t/multi-material-id/395852/2 "2009-08-03T19:52:45Z")

</div>

have you tried baking the textures? thats working realy well for me atm.

---

<div class="post-metadata">

**Author:** ![anon\_28146080](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@anon\_28146080](https://discussions.unity.com/u/anon_28146080)\
**Post date:** [August 4, 2009, 7:54am UTC](https://discussions.unity.com/t/multi-material-id/395852/3 "2009-08-04T07:54:22Z")

</div>

hi timbo, thanks for the reply, but baking cannot work because I have to change at runtime some materials on ID 1.  
My programmer says that it’s impossible to reach this parameter from scripting too, is that possible that there is something unavailable by code?

---

<div class="post-metadata">

**Author:** ![Dreamora](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/dreamora/32/91058_2.png) [@Dreamora](https://discussions.unity.com/u/Dreamora)\
**Post date:** [August 4, 2009, 8:01am UTC](https://discussions.unity.com/t/multi-material-id/395852/4 "2009-08-04T08:01:38Z")

</div>

There are no random assignements.  
The modelling application likely is just not storing them in the same order causing the hickup.

And you can reach about anything of importance in that case through coding in Unity Pro

---

<div class="post-metadata">

**Author:** ![anon\_28146080](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@anon\_28146080](https://discussions.unity.com/u/anon_28146080)\
**Post date:** [August 4, 2009, 9:24am UTC](https://discussions.unity.com/t/multi-material-id/395852/5 "2009-08-04T09:24:05Z")

</div>

It’s strange because in max file (source) the ID are ok and in Unity they are randomly messed up. But if we reimport the model in max (Unityzed) the ID are correct again. By the way we are swapping material using names and not the array#, that seems not working as we expect.

---

<div class="post-metadata">

**Author:** ![anon\_98078103](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@anon\_98078103](https://discussions.unity.com/u/anon_98078103)\
**Post date:** [August 4, 2009, 9:36am UTC](https://discussions.unity.com/t/multi-material-id/395852/6 "2009-08-04T09:36:53Z")

</div>

The problem is the following:

With this script one can modify the first material of a gameObject.

```auto
for (var go : GameObject in gos)  
{ 
  go.renderer.material = mat;
}

```

Trying to modify a specific element of the materials array of the renderer was not allowed:

```auto
for (var go : GameObject in gos)  
{ 
  go.renderer.materials[1] = mat;
}

```

The same was for the sharedMaterials array of the renderer. This obviously sounds strange but is how it is in reality… I may understand that changing the materials array is not allowed since one gets just the Instance of the material, but being not allowed to change the material accessing the sharedMaterial array was crazy.

The workaround that i discovered is copying the whole sharedMaterials array of the renderer in a temp array, change the needed material in the temp array and finally copy the temp array into the sharedMaterials array of the renderer. For more clarity:

```auto
for (var go : GameObject in gos)  
{ 
  var l : int = go.renderer.sharedMaterials.Length;
  for(var i = 0; i < l; i++)
  {
    if(...)
    {
      var tmp : Material[] = go.renderer.sharedMaterials;
      tmp[i] = mat;
      go.renderer.sharedMaterial = tmp;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Dreamora](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/dreamora/32/91058_2.png) [@Dreamora](https://discussions.unity.com/u/Dreamora)\
**Post date:** [August 4, 2009, 12:56pm UTC](https://discussions.unity.com/t/multi-material-id/395852/7 "2009-08-04T12:56:59Z")

</div>

go.renderer is a property.  
In such specific situations, at least in C#, you can not toy around with go.renderer.materials _directly, you would have_  
_`* *var themats = go.renderer.materials themats[i] = ....; go.renderer.materials = themats;* *`_  
_because all fields of go.renderer are otherwise read only_

---

<div class="post-metadata">

**Author:** ![anon\_98078103](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@anon\_98078103](https://discussions.unity.com/u/anon_98078103)\
**Post date:** [August 4, 2009, 1:30pm UTC](https://discussions.unity.com/t/multi-material-id/395852/8 "2009-08-04T13:30:43Z")

</div>

It’s exactly the same as I did even without knowing the details of it…

The point of being read only but however modifiable sounds a bit strange…

Thanks

---

<div class="post-metadata">

**Author:** ![anon\_86505217](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@anon\_86505217](https://discussions.unity.com/u/anon_86505217)\
**Post date:** [November 9, 2009, 4:15pm UTC](https://discussions.unity.com/t/multi-material-id/395852/9 "2009-11-09T16:15:28Z")

</div>

Hi lucaderiu!

Did you find a work around to this issue?? I´m having the same issue with a mesh that have 12 parts with 2 materials IDs; my programmer need that every piece have the same material in the ID 1… but for some odd reason Unity is messing up the model and 1 of the parts comes with the materials ID swapped! :S

I already checked in 3dsmax the IDs, they are fine and i even checked it at Motionbuilder and the same result… and even the ASCII fbx file. So it has to be the unity importer and haven´t found a solution yet…

Any help will be greatly appreciated!!

Thanks in advance!!

---

<div class="post-metadata">

**Author:** ![Paul\_Usul](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Paul\_Usul](https://discussions.unity.com/u/Paul_Usul)\
**Post date:** [November 11, 2009, 4:00pm UTC](https://discussions.unity.com/t/multi-material-id/395852/10 "2009-11-11T16:00:51Z")

</div>

Hey Dakkon, I have exactly the same problem, have you resolved this issue?

---

<div class="post-metadata">

**Author:** ![Sycle](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/sycle/32/543352_2.png) [@Sycle](https://discussions.unity.com/u/Sycle)\
**Post date:** [December 10, 2009, 2:42am UTC](https://discussions.unity.com/t/multi-material-id/395852/11 "2009-12-10T02:42:54Z")

</div>

Hi guys! I’ve been looking for a solution to this issue too and think I might have discovered an insight.

I have a bunch of meshes with two materials - the first material is the base, the second material is the ‘light’. It’s important that they’re in slot 0 and 1 respectively _(for my scripts)_

But on one particular object, Unity decided the ‘light’ material should be first, royally screwing things up.

So I swapped ID’s in MAX, but it stayed exactly the same. That’s when I realised the material order corresponded to the mesh’s face order. ie, whatever material “face #1” is using becomes the first material listed in Unity. I confirmed this by manually hunting down the first face and changing it to be the base material, and suddenly the order was right in Unity.

So it’s true that the assignment is not ‘random’, but it seems possible that it is stupid. _(considering face order is not something I can control as an artist)_

---

<div class="post-metadata">

**Author:** ![Paul\_Usul](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Paul\_Usul](https://discussions.unity.com/u/Paul_Usul)\
**Post date:** [December 10, 2009, 8:52am UTC](https://discussions.unity.com/t/multi-material-id/395852/12 "2009-12-10T08:52:23Z")

</div>

damn that sounds really really ugly. One of our artists resolved it by splitting the model and reattaching it in the material order. Sounds like it could collaborate your findings.

Is there a open source alternative?

---

<div class="post-metadata">

**Author:** ![anon\_80094797](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@anon\_80094797](https://discussions.unity.com/u/anon_80094797)\
**Post date:** [April 30, 2010, 2:47am UTC](https://discussions.unity.com/t/multi-material-id/395852/13 "2010-04-30T02:47:05Z")

</div>

Damn I’m running into the same problem. it would be difficult to determine what face to look for each id, especially when your importing multiple models expecting to change specific material id’s.

Examples:  
head with hair on it. (Could be different on models)  
chrome on car. (Would be different on models)

Is there any way to fix this?

---

<div class="post-metadata">

**Author:** ![anon\_80094797](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@anon\_80094797](https://discussions.unity.com/u/anon_80094797)\
**Post date:** [April 30, 2010, 10:00pm UTC](https://discussions.unity.com/t/multi-material-id/395852/14 "2010-04-30T22:00:08Z")

</div>

Bump

Can one of the mods comment? I submitted a bug report, I’m just wondering if there are any intentions on changing the way this works. I can see ways to get around this, but it would be nice to have it work when you bring in the max file.

---

<div class="post-metadata">

**Author:** ![jamexist](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jamexist](https://discussions.unity.com/u/jamexist)\
**Post date:** [February 5, 2012, 1:21pm UTC](https://discussions.unity.com/t/multi-material-id/395852/15 "2012-02-05T13:21:30Z")

</div>

It’s a bit late, but I have come over this exactly as PaulUsul’s way, but de-attaching and reattaching them again usually ends up with face normals problem and also if there are a lot of submeshes, imagine how frustrating it can be to sort every submesh’s name.

And if as Sycle says it takes the mesh’s first face, so what happens to for example 4th material order?! and in this case what is material ID for then?

---

<div class="post-metadata">

**Author:** ![anon\_14066448](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@anon\_14066448](https://discussions.unity.com/u/anon_14066448)\
**Post date:** [April 14, 2012, 3:00pm UTC](https://discussions.unity.com/t/multi-material-id/395852/16 "2012-04-14T15:00:26Z")

</div>

Is this problem still happening for fbx generated on 3dsmax files? It seems like I currently experience the same problem when I create an FBX from Maya file. Since Maya isn’t based on a meterial ids system like Max, for Unreal we had to append a prefix at the end of our materials names to make sure Unreal would re-assign materials at the proper position in the array on re-importation.

Maybe I should use maya files instead and Unity will take them based on their alphabetical order like the hypershade does?

Do we have something similar for Unity? I’m surprised how few post we can find for this problem. I guess it’s because peoples are mainly using only one material per object to save draw calls but how about PC developers?

Thanks for letting me know if there is anything to fix this issue!

---

<div class="post-metadata">

**Author:** ![tonyclifton](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/tonyclifton/32/503563_2.png) [@tonyclifton](https://discussions.unity.com/u/tonyclifton)\
**Post date:** [December 15, 2013, 2:18pm UTC](https://discussions.unity.com/t/multi-material-id/395852/17 "2013-12-15T14:18:10Z")

</div>

I am interested in a solution to this, too.

---

<div class="post-metadata">

**Author:** ![trzmiel](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/trzmiel/32/149784_2.png) [@trzmiel](https://discussions.unity.com/u/trzmiel)\
**Post date:** [December 17, 2013, 11:35pm UTC](https://discussions.unity.com/t/multi-material-id/395852/18 "2013-12-17T23:35:32Z")

</div>

2 hours lost because of this issue!!!  
I think the sollution of the Paul Usul is the best - deteach and attach each part in desired order.  
Thanks.

---

<div class="post-metadata">

**Author:** ![tonyclifton](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/tonyclifton/32/503563_2.png) [@tonyclifton](https://discussions.unity.com/u/tonyclifton)\
**Post date:** [December 18, 2013, 10:42am UTC](https://discussions.unity.com/t/multi-material-id/395852/19 "2013-12-18T10:42:22Z")

</div>

**trzmiel**  **Paul Usul** , yes, I tried that, too, and finally solved the issue. (in 3ds max)

- Apply the material you want for Element 0 to everything
- Detach the parts that should have a different material
- then apply the other materials to the detached parts
- select the part again that has the material that should be the Element 0 material
- and attach in the desired order the other parts again.

---

<div class="post-metadata">

**Author:** ![Singularity](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/singularity/32/388668_2.png) [@Singularity](https://discussions.unity.com/u/Singularity)\
**Post date:** [August 22, 2015, 8:46am UTC](https://discussions.unity.com/t/multi-material-id/395852/20 "2015-08-22T08:46:59Z")

</div>

Just in case anyone runs into this issue in the future and stumbles across this thread;

As of 2.75 you can reorder your materials in Blender and then reorder the mesh elements to match as per the helpful tutorial below.

[http://blairwillems.com/2013/05/unity-and-blender-quick-tip-on-order-of-materials-during-import/](http://blairwillems.com/2013/05/unity-and-blender-quick-tip-on-order-of-materials-during-import/)

Hope this helps someone.

[Next page](https://discussions.unity.com/t/multi-material-id/395852.md?page=2)
