flickering textures on using combinechildren

Hi! I have a texture atlas, which has several window textures. I wanted to have a single FBX plane which can display a rectangular part of the atlas, so as to show a single window. So I wrote this script :

var ulX : float;
var ulY : float;
var lrX : float;
var lrY : float;

function Start () {
		
    var dmesh : Mesh = GetComponent(MeshFilter).mesh;
    var dvertices : Vector3[]  = dmesh.vertices;
		
    var uvs : Vector2[] = new Vector2[dvertices.Length];
	
    uvs[0] = Vector2(ulX,ulY);
	uvs[1] = Vector2(ulX,lrY);
	uvs[2] = Vector2(lrX,lrY);
	uvs[3] = Vector2(lrX, ulY);
	
	dmesh.uv = uvs;
	
}

This script worked fine, until I thought that since they all are using the same material, they can be combined to get better performance. I created an empty gameobject and made all the meshes its children, and used combinechildren. But the meshes continued to show the original atlas texture instead of the rectangular parts that they were supposed to show.

I noticed that the meshRenderer of the meshed were getting disabled on runtime. So while the game was still playing in the editor I enabled it, but then, as the camera moved, the texture flickered between the atlas and the part that they were supposed to show.

Thanks for reading.
-Vatsal

If you’re running combine children in Start(), there’s a fair chance that it’s executing before your above script has applied the new mesh uvs, thus displaying the original texture coordinates.

As for the disabled mesh renderers on your original objects, that’s intended behavior. Combine children duplicates all child meshes into a larger mesh, then disables the mesh renderer on all original objects (though leaving the gameobject active, and still alowing them to be remapped via your script). When you reactivate one of these mesh renderers during runtime, you get 2 objects in the same place which will flicker on the screen as unity doesn’t know which one to render ontop, the combined mesh with the original uvs, or the single object with the modified ones.

If this is the problem, putting a small delay/yield in the start function of your combine children script should work, to make sure that your objects are remapped before they’re combined.