Collision function not working

I am following the unity tutorial, and I am following the step of collision detection. I have an object with a script that detects collision, both it and other objects have the box collider component. But when they collide the collision does not happen why is that?

private void OnTriggerEnter(Collider other){
        Destroy(gameObject);
        Destroy(other.gameObject);
    }

OnTriggerEnter is for colliders that have “Is Trigger” set in the inspector. For non-trigger colliders, you need to use OnCollisionEnter.

1 Like

I have all my prefabs with is trigger on

onCollisionEnter did not work either

Triggers will not collide with each other. One of them needs to not be a trigger.

2 Likes

At least one of the two objects needs to have a Rigidbody component in order for the OnCollisionEnter/OnTriggerEnter functions to fire.

Also, how are you moving the objects?

1 Like

I got the objects to collide with each other.
But the trigger seems to disappear after moving for a bit.
I thought it was the gravity, but the object still disappears with graity off.
how do I fix this

never mind, I got it thank you