I have a huge problem. I’m a game developer and currently trying to create a level with Lego buildings. So I export them as zmbx from mecabricks and import them to blender, combine the meshes (joined them into one) and then export it as fbx which I than can import into ue5. The problem is that the mesh has to many materials and nanite can’t handle a mesh with over 64 material slots (mine, a simple building, has around 650), each brick has a material, which is totally unnecessary cause the most of these materials have the same color/texture. They are called like „mb:o:234:199“, when the last number is the same (199) all these materials have the same color/texture.

Materials of the mesh example

And then for example other materials with the ending 134 are also the same … I saw that a lot of guys found a way to combine all materials into one. I tried some blender addons like creating an atlas, but for that you have to create a new uv map which my pc can’t handle because of the mesh (Rtx 3070ti ox, ryzen 7 5800x, 32gb Ram). And then I get a weird texture and the mesh is completely filled with random colors. I’m new to blender so I have no other ideas. Please help

  • 1
    $\begingroup$ What about grabbing the first occurence of a material with suffix :199 and then assigning this material to all other parts where another :199 material is used? You could then delete all materials except the first afterwards. $\endgroup$
    – taiyo
    Jun 29 at 11:06

1 Answer 1


Before exporting, creating atlases, uv maps and so on you could reduce the amount of materials to only the necessary ones. Go over to the Scripting workspace and create a new .py file with the following script. Select your object in object mode and run the script:

import bpy

context = bpy.context
obj = context.object
mesh = obj.data

suffixes = [':199', ':44']  # add more suffixes

for suffix in suffixes: 
    mat_slots = obj.material_slots

    basemat = None
    basemat_index = -1

    for index, slot in enumerate(mat_slots):
        mat = slot.material
        if mat and mat.name.endswith(suffix):
            basemat = mat
            basemat_index = index

    if basemat:
        for face in mesh.polygons:

            slot = mat_slots[face.material_index]
            mat = slot.material
            if mat and mat.name.endswith(suffix) and mat.name != basemat.name:
                    face.material_index = basemat_index

        for i in range(len(mat_slots) - 1, basemat_index, -1):

            mat = mat_slots[i].material
            if mat and mat.name.endswith(suffix) and mat.name != basemat.name:

                obj.active_material_index = i

This will assign the first found material with suffix :199 to all faces which have another material (not the first found) with suffix :199 and remove these material variations afterwards.

Edit: updated script to process multiple suffixes

Then it will process the next suffix (:44) and so on.

  • $\begingroup$ Thank you! I searched exactly for that! But there is a problem there aren’t only materials ending with :199. there are lots of material groups with the same suffix. Is it maybe possible to change that script, so it goes threw all materials and combine all with the same suffix? $\endgroup$
    – ThrallWoW
    Jun 29 at 15:59
  • $\begingroup$ Sure, thats what i meant with "improve the hard coded parts". I'll update my answer. $\endgroup$
    – taiyo
    Jun 29 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .