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

  1. 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.

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.