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.