Dadu Khan
Dadu Khan

Reputation: 379

Why does collision detection work in editor but not in android build? (AR Foundation)

I am building an augmented reality app using ar foundation. I need to detect a collision between two cubes. The cubes both have a box collider and a rigid body attached to them. When I run the scene in the editor everything works fine but when I build it for android and then test it won't detect any collisions. Could it be because when one of the cubes is spawned it is already touching the other one?

enter image description here

I'm pretty sure its an issue with Unity and not my code but here is some of it just in case. I have also posted on Unity Answers here

void OnCollisionEnter(Collision collision)
{

    Debug.Log(collision.gameobject.name);
    
    if (collision.gameObject.tag == col_tag)
    {
        if (collision.gameObject != first && first != null)
        {
            //stuff
        }
        else
        {
            point = collision.contacts[0].point;
            first = collision.gameObject;
        }
    }
}

Upvotes: 1

Views: 889

Answers (1)

Poke Clash
Poke Clash

Reputation: 96

try using void OnTriggerEnter. In the box collider activate IsTrigger and try to use this script:

void OnTriggerEnter (Collider collision)
{

    Debug.Log(collision.gameobject.name);
    
    if (collision.gameObject.tag == "col_tag")
    {
        if (collision.gameObject != first && first != null)
        {
            //stuff
        }
        else
        {
            point = collision.contacts[0].point;
            first = collision.gameObject;
        }
    }
}

Upvotes: 1

Related Questions