Search Issue Tracker

Fixed

Fixed in 2022.2.13f1, 2023.1.0b10, 2023.2.0a8

Votes

0

Found in

2022.2.8f1

2023.1.0b5

Issue ID

UUM-28747

Regression

No

OnTriggerExit2D not called when colliders are disabled due to getting unloaded

--

-

1. What happened
This project has the 2D setting "Callbacks On Disable" turned on. This setting is documented as:

"If the Collider2D being disabled has at least a single contact with another Collider2D then with this property set to true, a callback would be produced.
...
Only "OnCollisionExit2D" or "OnTriggerExit2D" will be called by disabling a Collider2D."

As expected, deactivating a GameObject when it's overlapping a different GameObject, and both have Collider2D's results in OnTriggerExit2D. But if I instead deactivate the GameObject by unloading the scene it is in, no OnTriggerExit2D is invoked.

Since both OnDisable and OnDestroy is called on objects when their scene is unloaded, my assumption here was that OnTriggerExit2D also should be called, but that is not the case.

This bug was originally found in Unity 2021.3.16f1, so it's been around for a while

2. How can we reproduce it using the example you attached
- Load Scene A, and enter play mode
- Use the "Load Level" button to load Scene B
- Move the black box so it intersects with the red box with A/D or the arrows, and note that "On Trigger Enter 2D" is printed to console.
- Use the "Deactivate Object" and "Activate Object" buttons to turn the red box on and off. Note that "On Trigger Enter 2D" and ""On Trigger Exit 2D" is printed to console
- use the "Unload Level" and "Load Level" buttons again to unload and load Scene B. Note that "On Trigger Exit 2D" is _not_ printed to console, while "On Trigger Enter 2D" is!
- expected behaviour is that unloading the scene should cause an OnTriggerExit2D to be raised.

  1. Resolution Note (fix version 2023.2.0a8):

    Fix for this issue will be available on Unity 2023.2.0a8 and above

  2. Resolution Note (fix version 2023.1.0b10):

    Fix for this issue is available on Unity 2023.1.0b10 and above

  3. Resolution Note (fix version 2022.2.13f1):

    Fix for this issue is available on Unity 2022.2.13f1 and above

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.