- Home /
Problem with TriggerEnter/Exit Execution Order
I'm having an odd issue where some of my in-game objects are running OnTriggerExit and OnTriggerEnter in a different order.
For context, I have a number of tools that spawn on two tables, each table with a Trigger collider on it. When the tools enter and exit the trigger collider, I run some code like enabling/disabling gravity on them. (Note that the smaller colliders are "spawn bounds" so the tools aren't hanging over the edge of the trays). When I run a function to randomize the tool order (and swap their positions), some of the tools don't have gravity and start to float upwards! After digging a little, I found that in some cases, the tools were running OnTriggerEnter for the new table, then OnTriggerExit for the old table after it (which is what disabled the gravity on them). I logged that both functions were running in the same frame, but the order was inconsistent. Some tools ran Exit->Enter, while others did Enter->Exit.
Any ideas how to control this behavior so that OnTriggerExit for the old table runs before OnTriggerEnter on the new one?
Unity version is 2019.4.19 if relevant.
Thanks
Your answer
Follow this Question
Related Questions
Did triggers inside loaded gameobjects break in a recent update? 0 Answers
Fastest way to check for bounding box partially or fully inside another bounding box? 1 Answer
How do you avoid collisions when teleporting CharacterControllers? 0 Answers
Is there any way to see exactly which triggers are overlapping? 1 Answer
How do I solve the Box Collider (3D) Edge / Corner Collisions problem? 5 Answers