Search Issue Tracker

By Design

Votes

0

Found in

2017.1.0b5

Issue ID

910045

Regression

Yes

OnTriggerEnter2D is triggered one more time after the colliding object has been destroyed

Physics2D

-

OnTriggerEnter2D is triggered one more time after the colliding object has been destroyed

To reproduce:
1. Use the attached project or download 2D Platformer sample from the Asset Store. The attached project has an extra debug line on the remover script
2. Load Level scene and press play
3. Move the player at the top of UFO and wait for him to die
4. When the player dies and touches the water a null reference exception is thrown

Actual Result: A null reference exception is thrown when the player touches the water at the bottom of the scene
Expected Result: It shouldn't throw a null reference exception

Extra notes:
If you put a breakpoint in the offending line you will notice that OnTriggerEnter2D is triggered twice. The second time it tries to access a destroyed object and it throws a null reference exception.

The behaviour is quite weird because it doesn't reproduce if the player dies in the lower platforms of the level. It reproduces only if the player dies on top of the UFO or the upper platforms.


Reproducible: 2017.1.0b5, 5.6.0p4
Not reproducible: 5.5.3p3

Comments (2)

  1. Ratstail91

    Feb 04, 2019 06:42

    This issue has resurfaced in 2018.3.0f2. Removing Destroy(gameObject) solves the issue, so I'm at least assuming it has.

    Both objects have multiple colliders on themselves and their children, for what it's worth.

  2. Ammita

    Aug 24, 2017 12:35

    I have same problem after opening old project (Unity ~5.2-5.3, project worked there perfectly) in Unity 2017.1.0f3 - OnTriggerEnter2D() was called twice instead one.
    Possible reason:
    When i added one more collider to player's hero for test, OntriggerEnter2D() was called three times instead one time (after adding collider, hero object had 3 colliders). It makes me suppose that the problem is that the trigger-object does not have time to be destroyed (or some else reason), and each hero's collider calls a OnTriggerEnter2D(). Or it happens beacause of some physics rules changes in the new version of Unity, because in older versions (~5.2-5.3) it worked fine.
    P.S. Sorry for my english.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.