## How to combine the meshes in child gameobject?

2017/10/10 02:42
We had to meet Drawcall problem in Mobile game developing using unity 3D.
You should solve it by 2 combination way.

1. Make shard material.
2. Combine mesh.

I writing down about "Combine mesh"

1. Make next script as CombineChild on Unity3D

```using UnityEngine;
using System.Collections;

[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class CombineChild : MonoBehaviour
{
void Start()
{
Matrix4x4 thisTransform = transform.worldToLocalMatrix;
MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
CombineInstance[] combine = new CombineInstance[meshFilters.Length];
int i = 0;
while (i < meshFilters.Length)
{
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = thisTransform * meshFilters[i].transform.localToWorldMatrix;
meshFilters[i].gameObject.SetActive(false);
i++;
}
transform.GetComponent<MeshFilter>().mesh = new Mesh();
transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine); //, true, true, true);

transform.GetComponent<MeshFilter>().mesh.RecalculateNormals();
transform.gameObject.SetActive(true);
}
}
```

2. and Please attach to parent gameobject.

Cheers
{"ft_lang_label":"__label__en","ft_lang_prob":0.5443411,"math_prob":0.8553782,"size":1434,"snap":"2019-51-2020-05","text_gpt3_token_len":322,"char_repetition_ratio":0.16783217,"word_repetition_ratio":0.37419355,"special_character_ratio":0.23012552,"punctuation_ratio":0.24279836,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9528928,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-07T14:53:14Z\",\"WARC-Record-ID\":\"<urn:uuid:daa4edb3-f579-4248-99d4-a68683805c8b>\",\"Content-Length\":\"63754\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:32bb8709-6814-4efd-a850-0123b01bdc38>\",\"WARC-Concurrent-To\":\"<urn:uuid:e249a90f-23e4-4eab-894d-870b183fb3a2>\",\"WARC-IP-Address\":\"101.79.49.123\",\"WARC-Target-URI\":\"http://wolfpack.pe.kr/945\",\"WARC-Payload-Digest\":\"sha1:7ID3OFPEXSJAOVPJH7IFM2KYYL2465GE\",\"WARC-Block-Digest\":\"sha1:PISZM7RVERRDHMB6L2V5QES5P7I4JQRL\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575540499439.6_warc_CC-MAIN-20191207132817-20191207160817-00105.warc.gz\"}"}