Combine meshes result in a larger file size on export (GLTF)

Hi guys, I have a script to combine meshes which share the same material. The obvious goal is to reduce the draw calls count and it works perfectly (from 500 draw calls to about 70).

I need to export the scene in GLTF compressed format (.glb) to use it on web, I am using this open source project by KhronosGroup.

I’ve noticed that after the combine operation, my exported file has a larger file size: from 2 MB (not combined) to about 5.8 MB (combined). I don’t understand the reason , since materials and textures should be the same.
Does anyone know why is this happening?

Hi @Bunny83 , thanks for the answer. The script to combine meshes is almost the same as the one provided by Bunzaga [on this thread][1]:

 using UnityEngine;
 using System.Collections;
 
 public class MeshCombiner : MonoBehaviour
 {
     public void Awake()
     {
         ArrayList materials = new ArrayList();
         ArrayList combineInstanceArrays = new ArrayList();
         MeshFilter[] meshFilters = gameObject.GetComponentsInChildren<MeshFilter>();
 
         foreach (MeshFilter meshFilter in meshFilters)
         {
             MeshRenderer meshRenderer = meshFilter.GetComponent<MeshRenderer>();
 
             if (!meshRenderer ||
                 !meshFilter.sharedMesh ||
                 meshRenderer.sharedMaterials.Length != meshFilter.sharedMesh.subMeshCount)
             {
                 continue;
             }
 
             for (int s = 0; s < meshFilter.sharedMesh.subMeshCount; s++)
             {
                 int materialArrayIndex = Contains(materials, meshRenderer.sharedMaterials~~.name);~~

if (materialArrayIndex == -1)
{
materials.Add(meshRenderer.sharedMaterials~~);
materialArrayIndex = materials.Count - 1;
}~~
combineInstanceArrays.Add(new ArrayList());

CombineInstance combineInstance = new CombineInstance();
combineInstance.transform = meshRenderer.transform.localToWorldMatrix;
combineInstance.subMeshIndex = s;
combineInstance.mesh = meshFilter.sharedMesh;
(combineInstanceArrays[materialArrayIndex] as ArrayList).Add(combineInstance);
}
}

// Get / Create mesh filter & renderer
MeshFilter meshFilterCombine = gameObject.GetComponent();
if (meshFilterCombine == null)
{
meshFilterCombine = gameObject.AddComponent();
}
MeshRenderer meshRendererCombine = gameObject.GetComponent();
if (meshRendererCombine == null)
{
meshRendererCombine = gameObject.AddComponent();
}

// Combine by material index into per-material meshes
// also, Create CombineInstance array for next step
Mesh[] meshes = new Mesh[materials.Count];
CombineInstance[] combineInstances = new CombineInstance[materials.Count];

for (int m = 0; m < materials.Count; m++)
{
CombineInstance[] combineInstanceArray = (combineInstanceArrays[m] as ArrayList).ToArray(typeof(CombineInstance)) as CombineInstance[];
meshes[m] = new Mesh();
meshes[m].CombineMeshes(combineInstanceArray, true, true);

combineInstances[m] = new CombineInstance();
combineInstances[m].mesh = meshes[m];
combineInstances[m].subMeshIndex = 0;
}

// Combine into one
meshFilterCombine.sharedMesh = new Mesh();
meshFilterCombine.sharedMesh.CombineMeshes(combineInstances, false, false);

// Destroy other meshes
foreach (Mesh oldMesh in meshes)
{
oldMesh.Clear();
DestroyImmediate(oldMesh);
}

// Assign materials
Material[] materialsArray = materials.ToArray(typeof(Material)) as Material[];
meshRendererCombine.materials = materialsArray;

foreach (MeshFilter meshFilter in meshFilters)
{
DestroyImmediate(meshFilter.gameObject);
}
}

private int Contains(ArrayList searchList, string searchName)
{
for (int i = 0; i < searchList.Count; i++)
{
if (((Material)searchList*).name == searchName)*
{
return i;
}
}
return -1;
}
}
I’ve also tried [this payed solution from the Asset Store][2] for combine meshes, with the same result on the export.
*[1]: https://answers.unity.com/questions/196649/combinemeshes-with-different-materials.html*~~
*[2]: https://assetstore.unity.com/packages/tools/utilities/easy-combine-70059*~~