Manage materials order

Manage materials order

Anonymous
Not applicable
18,158 Views
11 Replies
Message 1 of 12

Manage materials order

Anonymous
Not applicable

Hi everyone,

I've created a modular assets pack in Maya 2017 for houses assembling in UE4. Many object have multiple materials so I got multiple material slots into the engine. The problem is that when i assigned the materials in Maya, I didn't respected any particular order and now in the engine I have the material slots in different orders. What I need to know if there is a way to change the order of the materials in Maya. Could someone help me please?

0 Likes
Accepted solutions (1)
18,159 Views
11 Replies
Replies (11)
Message 2 of 12

mspeer
Consultant
Consultant

Hi!

 

I am a bit confused about what you mean with "material slots" and order.

It reminds of someone asking how to burn files in a specific order on a CD so they will be shown in the right order at another computer in a file viewer. You can't control this, you can try to create a order by naming or file-creation date or anything else, but if someone uses a different sorting algorithm it's useless.

 

The best chance to preserve an order (or make an order reproducible) is by creating names in an alphabetical order (this can also be "name_01", "name_02", ...).

0 Likes
Message 3 of 12

Anonymous
Not applicable

Ok, I'll try to explain to you what I mean clearer. I also attach two images to show you what's my problem. In the image "01" there are two objects of my asset pack, I applied the same materials on both the objects but as you can see in the image in the first object the order of the materials is: "Wood_01"; "Concrete_01" but in the second object the order is: "Concrete_01"; "Wood_01". 

Now... When I import the FBX into the engine, it creates the material slots I mentioned, following the order I used when I first applied the materials in Maya (as you can see in image "02"). The true problem is that, by creating a blueprint in UE4 that should allow me to change the material in its own material slot (for each object), it happens that the material is applied on the wrong part of the object, since the materials order is inverted. So I need to change the materials order in Maya before exporting the FBX. 

0 Likes
Message 4 of 12

mspeer
Consultant
Consultant
Accepted solution

Hi!

 

1. The Object groups / materials are indeed in a specific order inside Maya

 

2. If you can import and see the same order in a game engine, there is no problem inside Maya or the FBX file.

 

3. With just 2 materials you can't say order is simply inverted i recommend to test this with 4 or more materials.

Anyway, you don't have any control from inside Maya about a tool in an other software, so you can't do anything inside Maya to force Maya and the other software to show the same order.

0 Likes
Message 5 of 12

Anonymous
Not applicable

Sorry to jump a necro thread but this might help people who are looking at similar problems.

 

The indexing of materials on a mesh in maya is the order in which they are added to the mesh. If you are combining meshes together you can control the order in which you add them.

 

If you have an existing mesh you separate a mesh into pieces, each with a single material on it. You can then combine them in order to get the desired indexing.

 

In Unity using FBX import the material order (indexing) is based off the maya mesh. So you can control the index and swap materials using index numbers.

 

Guessing other engines would do it similar.

Message 6 of 12

Anonymous
Not applicable

Hi,

I was figuring out the same issue how to get the correct order of the materials per object.

Following code should go through all the faces in creation order per selected object and find the material in it.

The order these materials appear in is the order they are in FBX files. The end result objMaterials array shows that.

 

import Maya.cmds as cmds

 

objMaterials = []

obj = cmds.ls(sl="True")
allFaces = cmds.polyEvaluate(obj,f=True)
for faces in obj:
      #print faces
      for face in range(allFaces):
          #print face
          iteFace = faces+".f["+str(face)+"]"
          cmds.select(iteFace)
          cmds.hyperShade(smn=True)
          material = cmds.ls(sl=True)
          #print material[0]
          if not material[0] in objMaterials:
              objMaterials.append(material[0])

 

Text editor didn't do nice indenting 🙂

0 Likes
Message 7 of 12

Anonymous
Not applicable

You can also expose the nodes inside the node editor. Click your geo and then the double arrow to view whats connected. You'll find the Named material"skin_001" is actually at the root lambert8sg. Renaming the lambert8sg to what would be in order will help. So example being... I have skin_001 and skin_002. 001 is at its root lambert7sg and 002 at its root is lambert6sg. This is due to the order they we're assigned in the reading above. When importing to engine element 0 will be skin_002 and element 01 will be skin_001. Renaming the lambert7sg to mat_a and lambert6sg to mat_b will now allow your materials to come in properly as skin_001 as element 0 and skin_002 at element 01.

Nice!

0 Likes
Message 8 of 12

Anonymous
Not applicable

sg stands for shader group - this can also be found in the hypershade. Rename them there if you want and switch between tabs to refresh the page and watch their placement in line update. 

0 Likes
Message 9 of 12

marshallwKF5EW
Explorer
Explorer

This is an old thread so perhaps this updated fix is well known - but thought I'd share:

If you want to force a specific material order in Maya so that the material slots will match that order when imported into UE4 , use this naming convention on your materials:
In maya - use a prefix of "M_ "  and suffix of "_skin000"  or "_skin001" etc and that will force that order.
Example:
M_MaterialName_skin000  (this will be the first material slot)

M_MaterialName_skin001

M_MaterialName_skin002

M_MaterialName_skin003 

Message 10 of 12

marius_andre_elgsaasWVPYX
Community Visitor
Community Visitor

This does NOT work. See attachment

marius_andre_elgsaasWVPYX_0-1698925012360.png

 

0 Likes
Message 11 of 12

marshallwKF5EW
Explorer
Explorer

Can you post the material names in Maya that you exported?  I used this process weekly - and it works if I name it correctly in Maya, and choose "reset to FBX" when Unreal prompts me on import if material names have changed.

I dont see the suffix of "_skin001" at the end of your materials, if you look at the "Slot Name" in your unreal screenshot.

0 Likes
Message 12 of 12

marshallwKF5EW
Explorer
Explorer

See attached picture.