- Home /
Strange order FixedUpdate and OncollisionEnter
In my scene I am logging the motion of objects (ball and baseball bat) in order to replay this after the action. I also log if the ball collides with the bat and log this as a special entry.
Now when I replay the log entry by entry I notice that at the time of contact there are two entries that have the same position of the ball and the bat. One is marked as contact entry, the other is a regular entry. I want to correct this, but there is something I don't understand.
The strange thing is that the contact entry is logged before the regular entry. The regular entries are logged in FixedUpdate, the contact entry is logged in OnCollisionEnter. According to the execution order (https://docs.unity3d.com/Manual/ExecutionOrder.html), FixedUpdate is called before OnCollisionEnter, so my expectation is that the regular entry would come before the contact entry.
This would make it easy to fix, just change the type of the last created entry. But since the order is the other way around, it will be harder to fix. I can not set a boolean in OnCollisionEnter to prevent creating the entry in FixedUpdate, because it will not be called anymore in this cycle. And it would create a terrible dependency; the logging script is a base class that is used in multiple places, I don't want to create a dependency to a specific script.
The calls are in separate scripts, but I have not set any preferred script execution order. Could it be that OnCollisionEnter of one script is called before FixedUpdate on another script? Or are all FixedUpdate calls handled before OnCollisionEnter calls in the same cycle?
Thanks!
[Edit] even with a specific script execution order, I set the script that detects the collision to +50, still the contact entry comes before the regular entry.
Your answer
Follow this Question
Related Questions
Calling a function from FixedUpdate by collision with an object 0 Answers
Will a force applied in OnCollisionEnter be more jittery than a force applied in FixedUpdate ? 0 Answers
OnTriggerStay execution order/rate 4 Answers
Are rigidbodies only moved in the physics-loop? 1 Answer
OnCollisionEnter inside FixedUpdate? 1 Answer