- Home /
Race conditions in Unity - Is this a problem?
Hi there,
I think I know the answer to this, but I've not found it definitively via my searches (always hard to pinpoint the exact wording isn't it?).
I'm using a colliders OnTriggerEnter() and OnTriggerExit() to keep a list of potential targets in range of my turret. The search for a new target is done via the Update() script. If it's possible that OnTriggerExit() could be called while Update() was still doing its checking, I could end up in a nasty little situation of suddenly attacking an out-of-range enemy.
I can (of course) factor this into my code, but it would all get very messy with additional double-checks for the various scenarios.
So... Could OnTriggerExit() and Update() be called concurrently?
Answer by Firelight · Mar 17, 2015 at 04:16 PM
No ! It can't be called, you can look there to see the order of execution :
http://docs.unity3d.com/Manual/ExecutionOrder.html
Even if there are multiple events in the same frame, update is called after the physics events.
Awesome! thank you. So basically, everything is single-threaded. Although I question this from a performance perspective, I'm thrilled from a coding perspective!
Your answer
