Search Issue Tracker
By Design
Votes
0
Found in
2021.3.41f1
2022.3.39f1
6000.0.12f1
Issue ID
UUM-77259
Regression
No
OnTriggerExit2D is called before OnTriggerEnter2D for same object when Instantiating a GameObject in same position of destroyed object
How to reproduce:
1. Open the attached “Piggy Games Test.zip” project
2. Open the “SampleScene”
3. Enter Play Mode
4. Observe the Console Window
Expected result: No errors are shown and OnTriggerExit2D is called after OnTriggerEnter2D
Actual result: OnTriggerEnter2D is called after OnTriggerExit2D and causes an error “MissingReferenceException”
Reproducible in: 2021.3.41f1, 2022.3.39f1, 6000.0.12f1
Reproducible on: Windows 11
Not reproducible on: No other environment tested
Note: Sometimes may take some time to get the error
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
- Required SpriteMask class (ID 331) is stripped when "Strip Engine Code" is enabled
- “Maximized serialized file backup not found” error is thrown when minimizing a window in a newly opened project
- Build stack trace contains invalid lines when building with IL2CPP using scripts with delegates containing generic types in the signature
- Entities Systems window has a “Show Full Player Loop” dropdown which does nothing when clicked after enabling “Show Full Player Loop”
- Entities Hierarchy Search “Show/Hide” button’s Lens Icon is blurry when the Editor is on an external monitor
Resolution Note:
The issue here lies with the way you are adding and removing the enemies from the “_targets” element. Since both archers can target the same Enemy, that creates the issue. Once one archer Destroys the Enemy, the second archer cannot access to Destroy the Enemy since the value is already null in the list.
The fix to this could be that both archers have different lists of targets and couldn’t target an enemy that is already in the other archers list of targets. Another suggestion could be that you remove the specific Enemy that was hit, and not the first entry in the “_targets” list.