So I’m trying to have on OnTriggerEnter2D function – simple, right? Well, I had it working before I rewrote script (was really sloppy before rewriting) and now it won’t work even though (as far as I can tell), the code is fine.
void OnTriggerEnter2D (Collider2D colsn)
{
// Do stuff
}
The problem: The function does not get triggered at all. Not with trigger/trigger or trigger/non-trigger collisions
The object has a BoxCollider2D that is set to trigger and the incoming collider is not a trigger.
I’ve done this hundreds of times with no problems. Am I blind to an obvious typo?
Using 5.6.1f1.
Any help would be greatly appreciated!
EDIT: And yes, the script is on the correct object and no errors are disabling the script and nothing disables the collider on the object and it is enabled from start.
UPDATE: So I tested things and found that no OnCollision/Trigger events fire for some reason. I’ve tried re-adding the collider, I’ve tried disabling scripts, I’ve played around with layers and the collision matrix, everything is as it should be.
I have no idea what is wrong here, but it’s only this one function on one object that is not working (as far as I know at least). Of course, it has to be the most important one
Also to clarify further, the Monobehavior containing the above method goes on the object that has the Rigidbody2D and some kind of Collider2D, and it has to hit another object that has a Collider2D marked as Trigger.
Contrary to intuition, you do NOT put it on the actual trigger area, you put it on the thing entering the trigger. I got it wrong just now trying it out, but quickly corrected it to be on the moving object and it worked fine.
Just for fun I flipped my scene over, stuck a Rigidbody2D on my Trigger-flagged ground, marked my falling object as isKinematic, and caused the ground to fall on the object (where my script was). As expected, OnTriggerEnter2D() fired just fine.