Modifying the CombineChildren script

I’m trying to mod the Combine Children script so that once I’ve worked out what I want visible for a level, I do a combine to stop seams in the model from appearing on the iPhone. Tested the concept and it works.

When I combine a mesh I get between 2-5 new models depending on how many different textures are in the mesh. That’s fine.

This is the bit of code that’s spitting out the meshes:

GameObject go = new GameObject(Room);
go.transform.parent = transform;
go.transform.localScale = Vector3.one;
go.transform.localRotation = Quaternion.identity;
go.transform.localPosition = Vector3.zero;
go.AddComponent(typeof(MeshFilter));
go.AddComponent("MeshRenderer");
go.renderer.material = (Material)de.Key;
MeshFilter filter = (MeshFilter)go.GetComponent(typeof(MeshFilter));
filter.mesh = MeshCombineUtility.Combine(instances, generateTriangleStrips);

‘Room’ is passed in as the name of the mesh to combine. After running I get 2-5 meshes all named the same. For Example:

PARENT
   ROOM1
   ROOM1
   ROOM1

What I want is for them to be grouped under a parent so I can choose to render the group or not. So basically this:

PARENT
   ROOM1
        ROOM1
        ROOM1
        ROOM1
   ROOM2
        ROOM2
        ROOM2
   ROOM3
etc.

How can I create an empty GameObject then add the new meshes to that new game object.

Sure this is simple - but I’m just not getting it :slight_smile:

I might be able to answer parts of your question.

This code finds a named “container” game object, instantiates a prefab as a gameobject and sets the parent of that new gameobject to the container

GameObject tileContainer = GameObject.Find("TileContainer");
				
tile = (GameObject)Instantiate(tilePrefab, new Vector3(0,0,0), Quaternion.identity);
tile.transform.parent = tileContainer.transform;