I know that FixedUpdate happens before the OnTrigger/OnCollider functions, but is there a way to change this? I have an object which moves around the scene in fixedupdate and I need to be able to check if it is colliding with another object, which I am currenty doing with a variable which changes in OnTriggerEnter and OnTriggerExit, but because FixedUpdate is before these and it is moving every fixedUpdate this doesn’t work. Any suggestions on ways to get around this?
The FixedUpdate is not tied, in any way, to physics callbacks. The FixedUpdate is simply part of the player loop and it calls things like 2D/3D physics, animation, scripts etc.
The OnTrigger/OnCollision callbacks are called by physics itself at the end of a simulation step. When the simulation step runs is controlled by Physics2D.simulationMode which, by default, is set to run during the FixedUpdate player-loop but it can be per-frame or manually via script. My point here being that the callbacks are tied to when the simulation happens.
You don’t need to rely on those callbacks, there are plenty of queries that allow to you perform this check that work whenever you need them, including ones that check if you’re in contact with anything. Indeed, you can ask for all the details of the contacts if you wish.
If you only need to know if there’s a contact then you can use the IsTouching queries to determine this. Many of the overloads allow you to also filter them in many ways.
Also note, if you check your “variable” per-frame then it’ll always be up-to-date so you can perform logic per-frame if you like.