- Home /
race condition?: 2 class, 1 gameobject w/OnTriggerEnter, do all function calls execute in B if destroy gameobject in A?
Scenario details:
- 1 GameObject has 2 classes attached, Class A & Class B, and obviously a trigger collider
- Class A has OnTriggerEnter where it executes Destroy(gameObject)
- Class B has OnTriggerEnter where it executes something
Upon trigger enter event, will everything in OnTriggerEnter in Class B get executed every time guaranteed?
HU$$anonymous$$$$anonymous$$, to be absolutly sure that is executed, put in OnDestroy() method a guard to check if this have been done, if dont call a function to do it.
also you can set custom execution order of scripts, and also, usually the objects are destroyed after the frame render (there exist DestroyInmediate()
to zero delay clear...), but, if you want to be completelly sure, just check completion on OnDestroy method on script B, or last option, improve design, just destroy itself on script B if its colliding A after done the task and avoid the root of the problem
Answer by reddtoric · Jul 13, 2019 at 10:03 PM
I ended up using inheritance. I thought there might be an issue if I used inheritance because of what I was doing but actually was not a problem.
Unsure if it is a race condition.