- Home /
Question by
silencer · Aug 29, 2011 at 05:58 PM ·
androidiosmeshcollideraddcomponent
AddComponent(MeshCollider) not working on Android/iOS
I have a map where I have to add collider data on the fly for visible objects in the renderer. Here's my function that does this:
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;
}
}
}
}
When building on PC/Web, this works flawlessly, and as expected. On Android, it doesn't seem to add the MeshCollider correctly. I confirmed this when attempting to Raycast against an object that was supposed to have its collider added on the fly. I get a NullReferenceException (basically no hit).
I know Android Typecasting is a bit more strict than for the PC/Web, but I'm at a loss as to why the above isn't working.
p.s - I tested the above code on android/iOS with basic cubes created in the editor, and the code works with those primitives.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612193717im_/https://answers.unity.com/themes/thub/images/avi.jpg)