Problem between using AddComponent(MeshCollider) on PC vs Android/iOS

Hi all, thanks for any help in advance with this issue.

I’ve been blocked 2 days on this particular issue, and made post in the mobile forums, and Unity answers, and no one seems to know what is happening here.

Here’s the link to the original thread:
http://answers.unity3d.com/questions/161313/addcomponentmeshcollider-not-working-on-androidios.html

Here’s the code in question:

function optimize(){

   var i : int;
    var objects : GameObject[] = FindObjectsOfType(GameObject) as GameObject[];

    for(i = 0; i<objects.Length; i++){

        if(objects[i].renderer  objects[i].name != "MagicObj"){

            if(objects[i].renderer.isVisible == true)
            {
                Debug.Log(objects[i].name);
                objects[i].AddComponent.<MeshCollider>();
                //objects[i].renderer.material.color = Color.red;
                objects[i].collider.enabled = true;
            }
        }
    }
}

For Web/PC builds, the code above works flawlessly. I know this because when I raycast against objects with the MeshCollider added on the fly, I get hit data back.

However on the Android, I’m not getting anything back, I get a NullReferenceException. Any ideas on what is happening here?

NVM, fixed.

This will never work on Android with a Combined Mesh component. The more you know! :slight_smile: