OnCollisionEnter2D seems to fail since 5.3 update.

Hi everyone,

I’m working on a Pong-like game in 2D. All physics is done with some Box Collider 2D and a RigidBody 2D on the ball. Everything worked well before. With the new update, 5.3, the game engine seems to fail to detect collisions on Box Collider 2D when they move. To be more precise, all collisions on the border of the screens works well with a Box Collider 2D, but the one on the player and the IA, also with some Box Collider 2D, seems to work completly randomly, nearly never detected, maybe around 1/10 collisions are detected. The ball bounce off everything, as if a collision is dectected.

I’ve put this code on the ball:

    void OnCollisionEnter2D (Collision2D other)
    {
        Debug.Log ("Collision");
    }

This code print normally when colliding with a wall, but around 1/10 or even less of the time when colliding with the player and IA. The only way to have collisions detected is to put the ball’s collision detection to “Continuous” but it’s overkilling some features of my game ( You can’t beat the IA, the only way you have to win is to have enough chance to have the ball go trought the IA’s collider at very high speed ).

I was working on this project with the Linux beta version of the Editor, everything worked well on the 5.2.X release ( the last one ). My problems started when upgrading to 5.3 and going back to Windows.

Thanks everybody for reading me.

Could you please provide a bug report?

Hello,

I don’t really know if it’s a new behavior due to the 2D physic upgrade for particles or a bug, so I didn’t have done a bug report. Maybe I have to do my physics with rigidbody now or by another way, I did not checked the docs if something changed. I’ve done it as usual I do with 2D physics.

Are you sure the problem didn’t start in 5.2.3 or 5.2.3 patch release?

There’s a fix on its way but without a bug case I cannot verify that it resolves your problem.

NOTE: Please attach a simple reproduction project to your bug report.

Hi,

I’ve just tried again the old version of my game on my Linux laptop using the 5.2.2f1 release ( latest Linux beta build available at this time. ) and it works just fine. The same code print on each collision. This problem appeared after I’ve added some 2D particles systems on my ball. I can’t make a bug report right now but I will do it this afternoon around 14:00. Thanks for checking this bug if it’s one.

Just FYI, 5.2.2 isn’t the latest version on 5.2.3p3 was the latest.

The 2D particle stuff has no impact on 2D collision detection i.e. the 2D physics wasn’t changed for that feature.

Thanks for doing a bug report!

If the 2D physics didn’t changed, then I may have messed something in my project. I will check everything up when I’ll can. I hope I did not make any error and took your time for nothing.

It’s never a waste of time. All bug reports are useful. I was really just trying to highlight that the issue may have started before 5.3 being as the recent problem was there in 5.2.3p3.

I did not used the 5.2.3p3 version, I’ve jumped from 5.2.2f1 on Ubuntu Linux to 5.3 on Windows, so I can’t say if that started with the 5.2.3p3 version. If this problem started in this version, then my problem is maybe the same.

Hi again, sorry for double post.

I’ve just send you a bug report with a project as close as mine but with only things needed to reproduce the bug. I hope this will help you.

You should eventually get an email. Let me know the bug case number and I can verify that it’s fixed.

My case number is 753115.

I have verified that the fix already in progress resolves your issue.

Thanks for the bug report.

Thanks

I was just about to post about this as well. The problem for us started with any version past 5.2.2 as MelvMay suggested.

One use case we’re having trouble with is when a trigger is animated with Mecanim, the collision is simply not registered.

  • If a trigger is spawned on top of another animated trigger, the collision will occur.
  • If a trigger is spawned and then moved into the animated trigger, the collision will fail.

I’ve attached a small test project where we can replicated this consistently on 5.3.0f4. If you open the Test scene and press space, you will see the collision fail. If you turn off the Animator component on the Target object and play the scene, the bullets will now hit without the trigger on the Target object animating.

We’re also having issues with some cases where collisions don’t register post 5.2.2 without adding a Rigidbody2D on all the involved objects, but we haven’t looked into this as much to provide a test case.

Edit:

I’ve submitted a separate bug report in case this is not a duplicate: 753232

2419063–165462–TriggerTest.zip (37.6 KB)

I just checked your case and it’s fixed. It would’ve stopped working in 5.2.3p1.

The fixes will be in 5.3.0p1 and 5.2.4 releases.

1 Like