Unity 2D (trigger) box colliders not working on 5.3?

Hi! I just updated to Unity 5.3. I find the new features amazing.

I was building this 2D game for an event I’m going in 5 days. It was almost finished (code worked perfectly, I only had to import the animations), but now triggers are not working!

There’s a wave following the player. If it touches you, you die. That simple.

I attached a script with this code in it:

void OnTriggerEnter2D(Collider2D col)
{
   print("Are you even colliding my friend?");
   if (col.gameObject.tag == "Player")
   {
       print("Working?");
       //Do stuff
   }
}

As you see, I added the “print” lines to test if it was colliding (tried changing them to Debug.Log just in case “print” was not working anymore for some reason, but it’s the same), but they’re not showing at all.

I realised it works if I move. It only fails if I just wait for the wave to touch me. I think it’s a Unity problem as that’s the way I always tested the wave.

Is this a Unity bug?

Thanks

2 Likes

I’m having a the same issue. Under Unity 5.1 I have no problems with OnTriggerEnter2D, everything works just right!!! However after I upgraded to version 5.3 OnTriggerEnter2D is not longer called all the times. Not sure yet, but for the way my game behaves I think OnCollisionEnter2D is not being called every time it’s required.

This is starting to get frustrating, every single version since 5.2.0 has had issues that prevent me from upgrading and I end up having to downgrade back to 5.1. 5.2.0 was buggy as hell, 5.2.1 and 5.2.2 had lots of severe performance issues, 5.2.3 solved most of the issues, but still was too slow on Android to take it seriously. 5.3 seems to have solved all the performance issues of the 5.2 series, but now it doesn’t behave properly on collisions, so for the fifth time in a row, I’m on my way to downgrade to 5.1.

1 Like

As my game is really small and the bug only affected the main character, I made something that makes me cringe:

rb.AddForce(new Vector2(1, 0) * Time.deltaTime * 0.000000001f);

The guy who tought me saw this, he would hit me hard in the face and kill himself.

EDIT:
He just saw it. He said we wouldn’t hit me… because “that’s for noobs”. He said he would electrify me until I learn.

Same problem here! Updated from 5.2 to 5.3, and now it doesn’t always register OnTriggerEnter2D.

I have the same problem! what to do?

Is the object with the trigger by any chance missing a kinematic Rigidbody2D?

If that’s the case, add a Rigidbody2D to your object, check ‘Is Kinematic’ and the trigger events should start registering promptly.

There is a noticeable delay now in 5.3 when you move a static trigger (which you shouldn’t be doing, anyway). I’ve noticed the change in behavior during beta and posted about it here.

4 Likes

The last patch that had functional 2D triggers for me was 5.2.2p4.

Now, OnTriggerEnter2D seems to be called later than it used to, and I need to at least double my physics time step to get performance similar to before the update. Whether a rigidbody is attached or not, and regardless of whether it’s kinematic on one or both colliding objects, the triggers are still firing much later than before. Occasionally, OnTriggerEnter2D is missed entirely. This has been happening since the first 5.2.3 release.

Please help Unity team, it’d be fantastic to be able to use 5.3.

Same issue here. I actually had no issues with OnTriggerEnter2D in 5.2.3 but it’s completely broken in 5.3.0.

Same here, I thought I was going nuts. I’ve tried kinematic rigid bodies on everything, triggers & oncollision2d & nothing is working.

The kinematic rigidbody thing is actually pretty funny.
If you check it as non-kinematic and play, trigger won’t work, but if you check it as kinematic while on trigger, it works.
It happens vice versa too.
I think all we can do is cry until Unity fixes this. Or give Godot a try!

Did you log a bug report from within your project?

I did, but I did it wrong (sorry, first time I ever report a bug). Now I did it again properly.

Thanks

The only known issue is that there can be a single physics-update delay when re-positioning bodies via the Transform rather than using Rigidbody2D.MovePosition (as is recommended). This has been fixed and is on its way to the patch release stream for 5.2 & 5.3.

Can you please provide me with bug case numbers please?

1 Like

Case number is 752059

1 Like

Thanks!

In my case, with Unity 5.3, when a character is falling on some object (say a spike) OnTriggerEnter2D will not fire until the character is landed and his velocity.y is zero ~90% of the time.

On 5.3 this, inside a OnTriggerEnter2D, will return zero most of the time:
Debug.Log( MyMainCharacter.GetComponent().velocity.y )

On 5.2 I had always the correct (negative when falling) velocity values.

And this is only an example, most of the OnTriggerEnter2D events now are delayed (or failing) for me too.

So I’ve just looked at case 752059 and it’s simply that you’re moving a static collider (something you should never do). Static colliders don’t actually detect contacts themselves, only dynamic/kinematic do. This is why moving a dynamic collider contacts things whereas moving a static collider doesn’t.

To make matters worse, the Rigidbody2D that your dynamic collider is attached to is sleeping so it never detects a collision nor does it have any reason to wake up. If you set the Rigidbody2D to ‘Never Sleep’ then it detects the static collider overlapping it.

If you set the dynamic body to not sleep then moving the static collider over the dynamic one causes a collision to be detected but that’s the (awake) dynamic one detecting that.This is stock Box2D.

I am following your reproduction steps of:
Triggers only working if Rigidbody is active.

This has been a kind of ‘undefined’ behaviour so I’m investigating what changed.

Bug reports are the only way to get these things resolved. Please create a simple reproduction project and submit a bug report.

Thanks.

I admit I’m pretty new to Unity, but it worked perfectly before Unity 5.3. My game was almost ready to be released.