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.
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.
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.
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.
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!
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?
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.