CombineMeshes and mesh colliders

Using the old CombineChildren, adding a mesh collider works as expected.

Using the script Eric5h5 made with CombineMeshes(), when you add a mesh collider it will automatically use the mesh in the filter, as expected. You can even double click it in the inspector and see the mesh. But it will not work as a collider.

Test:
Make 1 empty GO
make 2 boxes, remove box colliders make them children to GO
add script for combine meshes or CombineChildren
add a script that does something when clicking on GO

run
Drop a mesh collider on the parent

clicking on the combine meshes version will do nothing
Clicking on the CombineChildren version will work

I dont think this is a problem with the script for combine meshes, unless it needs something added.
I think this is a problem with the way CombineMeshes works. I dont have access to source and probably wouldnt know what to look for anyway.

I did try adding
RecalculateNormals();
RecalculateBounds();
after the combine, just to see what happened but it didnt help.

Combine3.js

// This script should be put on an empty GameObject
// Objects to be combined should be children of the empty GameObject
@script RequireComponent(MeshFilter)
@script RequireComponent(MeshRenderer)

function Start () {
   for (var child in transform)
      child.position += transform.position;
   transform.position = Vector3.zero;
   transform.rotation = Quaternion.identity;
   
   var meshFilters = GetComponentsInChildren(MeshFilter);
   var combine : CombineInstance[] = new CombineInstance[meshFilters.Length-1];
   var index = 0;
   for (var i = 0; i < meshFilters.Length; i++)
   {
      if (meshFilters[i].sharedMesh == null) continue;
      combine[index].mesh = meshFilters[i].sharedMesh;
      combine[index++].transform = meshFilters[i].transform.localToWorldMatrix;
      meshFilters[i].renderer.enabled = false;
   }
   GetComponent(MeshFilter).mesh = new Mesh();
   GetComponent(MeshFilter).mesh.CombineMeshes (combine);
   renderer.material = meshFilters[1].renderer.sharedMaterial;
}

Make objects go up(LMB) or down (ctrl LMB)
EditElev.cs

using UnityEngine;
using System.Collections;

public class EditElev : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	
	}
	
	public void OnMouseDown()
	{
        if(Input.GetKey( KeyCode.LeftControl )	)		//DOWN
		{
			transform.position += new Vector3(0, -.08f, 0); 
	
		}
		else
		{
			transform.position += new Vector3(0, .08f, 0);   //UP
	
	
		}
			
	}
  	
}

Reported as bug.

If anyone tries this and can confirm my results please post here.

On the plus side CombineMeshes seems much faster.
1024 objects, each object is a single quad.
CombineChildren 36 ms
CombineMeshes 22 ms

Additional information:

When using a skybox with a mesh that was combined with CombineMeshes, the sky renders over the mesh.

When changed to the old CombineChildren the skybox works.

Skybox shader applied to a sphere over the camera:

Shader "BlueSky/Skybox3" {
   Properties {
      _Color ("Main Color", Color) = (1,1,1,1)
      _MainTex ("Base (RGB)", 2D) = "white" {}
   }
   SubShader {
      Pass {
         Tags {"Queue" = "1000"}
         Cull Front
         ZWrite Off
         SetTexture [_MainTex] {
            ConstantColor [_Color]
            combine texture*constant
         }
      }
   }
}

Wow there was 230 bugs posted in 24 hours

The skybox thing is a possible issue, but the mesh collider problem isn’t really a bug as such. When you change a mesh, you can update the MeshCollider component by setting its sharedMesh property. There are some situations where you wouldn’t want to create a new mesh collider, so this is left as an option.

I understand that adding a collider is optional.
The issue is that even after you add a mesh collider, it doesnt work.

But using the old CombineChildren + mesh collider does work.

In my test process above, after running I dropped a mesh collider on it.

If you add a mesh collider in code at the end of the CombineMeshes script above it still wont work.

I just tried using Optimize() after combining as suggested on Answers. But it didnt fix either problem.

Case numbers
364060
364291

I figured out what was causing the skybox problem.

After CombiningMeshes I add a material as a new instance. It seems to only work when setting it with the sharedMaterial.

Is that a bug or expected?

Not sure if this is related but.

In the console I’m getting a warning message
“Shader ‘BlueSky/Skybox’: no subshaders can run on this graphics card”

I have a radeon 5870, I’m wondering if the shader is written wrong(ish).