Hey everyone,
I’ve been working on a project for a while now, but I hit a bump in the road on it recently.
I have an empty object with a rigidbody, box collider and some code to detect if anything enters it’s collider.
However, even though tons of things are entering it, OnTriggerEnter is not being called. I experimented around a bit, and I found that changing it’s rigidbody component in the inspector while the game is running would make OnTriggerEnter be called. So, I tried to replicate this in my code, by changing a few variables in my rigidbody component every frame. But it still wasn’t called.
Is there something that I’m missing? (Please don’t be one of those guys who just tells me to get Pro, not everyone can afford it)
Check out this page: Unity Manual - Colliders
Scroll to the bottom and look at the two tables. They show you what combinations of collider, trigger, rigidbody, isKinematic will collide together. Next, make sure the objects are not on collision layers that are set to ignore each other.
add rigid body to the object you wanted to be collide
In a 2D game it’s called OnTriggerEnter2D. (…in case anyone arrives here but is using Collider2D and RigidBody2D).
Tragically, there is no complaint if you if you define OnTriggerEnter on your 2D object. It just never gets called.
This you tube tutorial by Brackeys may help : Mastering Collision - Unity Tutorial - YouTube
Also I got frustrated for about an hour earlier today asking myself the same question, Why won’t collisions work anymore? Come to find out I hadn’t attached the script I wrote to the gameobject… haha.
You may or may not need to mess around with collision layers. For the small demo game I’m currently making for my portfolio all my game objects are on the default layer.