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.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- PlasticSCM NullReferenceException on entering the Play Mode when Unity Version Control tab is added to the layout
- Shortcut Helper Bar does not appear when enabling it and disabling it
- "Property (urp_ReflProbes_BoxMin) exceeds previous array size" warning spams console after switching platforms
- Have to change Input Mapping Path twice for change to take effect when Auto-Save is enabled
- No Duplicate option is available when right clicking States in the Animator Window even though it's available via Shortcut
Resolution Note (fix version 2023.2.0a8):
Fix for this issue will be available on Unity 2023.2.0a8 and above
Resolution Note (fix version 2023.1.0b10):
Fix for this issue is available on Unity 2023.1.0b10 and above
Resolution Note (fix version 2022.2.13f1):
Fix for this issue is available on Unity 2022.2.13f1 and above