Search Unity

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

Discussion in 'Scripting' started by silencer, Aug 30, 2011.

  1. silencer

    silencer

    Joined:
    May 16, 2009
    Posts:
    80
    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:
    Code (csharp):
    1.  
    2. function optimize(){
    3.  
    4.    var i : int;
    5.     var objects : GameObject[] = FindObjectsOfType(GameObject) as GameObject[];
    6.  
    7.     for(i = 0; i<objects.Length; i++){
    8.  
    9.         if(objects[i].renderer  objects[i].name != "MagicObj"){
    10.  
    11.             if(objects[i].renderer.isVisible == true)
    12.             {
    13.                 Debug.Log(objects[i].name);
    14.                 objects[i].AddComponent.<MeshCollider>();
    15.                 //objects[i].renderer.material.color = Color.red;
    16.                 objects[i].collider.enabled = true;
    17.             }
    18.         }
    19.     }
    20. }
    21.  
    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?
     
  2. silencer

    silencer

    Joined:
    May 16, 2009
    Posts:
    80
    NVM, fixed.

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