Obi Official Forum
(7.0) Still confused about how Obi physics updates in 7.0 - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: General (https://obi.virtualmethodstudio.com/forum/forum-5.html)
+--- Thread: (7.0) Still confused about how Obi physics updates in 7.0 (/thread-4206.html)



(7.0) Still confused about how Obi physics updates in 7.0 - kodra - 07-05-2024

Quote:In Obi 7 all solvers always run in parallel. Simulation starts in LateUpdate(), while still using a fixed timestep. This combines the best features from all ObiUpdater flavors and simplifies setup, as a result, the ObiUpdater component has been removed.



I still don't get it. LateUpdate() is called every frame. It's frame rate dependent. Then how Obi solvers runs in LateUpdate() while using a fixed timestep at the same time?

If I have game logic in LateUpate() (for example, update the bone's position), does Obi solver updates before or after it?


RE: (7.0) Still confused about how Obi physics updates in 7.0 - josemendez - 07-05-2024

(07-05-2024, 09:38 AM)kodra Wrote: I still don't get it. LateUpdate() is called every frame. It's frame rate dependent. Then how Obi solvers runs in LateUpdate() while using a fixed timestep at the same time?

What do you mean? all callbacks in Unity are frame rate dependent, since they're called during a specific frame. Framerate independence comes from scaling things by the amount of time passed since last time you did them, regardless of where they are done during the frame.

If you mean FixedUpdate vs LateUpdate, a common misconception is that FixedUpdate() is called every X seconds which is not at all the case. It's just that FixedUpdate is guaranteed to be called once per timestep as opposed to once per frame, which means it may be called zero, one, or multiple times per frame while LateUpdate is guaranteed to be called *exactly* once per frame.

So if 0.2 seconds have passed since the last frame and your fixed timestep is 0.05, Unity will perform 4 (0.2/0.05) back to back calls to FixedUpdate() during that frame. If 0.01 seconds have passed since the last frame, Unity won't call FixedUpdate that frame and will just accumulate the amount of time passed, and check again next frame whether enough time has passed to call FixedUpdate() again. You can easily replicate this behavior anywhere, this is pseudocode for what Obi does:

Code:
void LateUpdate()
{
   // accumulate time passed since last frame
   accum += Time.deltaTime;

   // while more than 1 timestep has passed, advance a timestep and subtract it from
   // the accumulator:
   while (accum >= Time.fixedDeltaTime)
   {
       InternalObiUpdate(Time.fixedDeltaTime);
       accum -= Time.fixedDeltaTime;
   }
}

If you're curious about what fixed timestepping means and how it's actually implemented in physics engines, I can recommend this timeless (no pun intended) classic:
https://gafferongames.com/post/fix_your_timestep/


(07-05-2024, 09:38 AM)kodra Wrote: If I have game logic in LateUpate() (for example, update the bone's position), does Obi solver updates before or after it?

It entirely depends on your script execution order.

kind regards,


RE: (7.0) Still confused about how Obi physics updates in 7.0 - kodra - 07-05-2024

(07-05-2024, 11:08 AM)josemendez Wrote: What do you mean? all callbacks in Unity are frame rate dependent, since they're called during a specific frame. Framerate independence comes from scaling things by the amount of time passed since last time you did them, regardless of where they are done.

If you mean FixedUpdate vs LateUpdate, a common misconception is that FixedUpdate() is called every X seconds which is not at all the case. It's just that FixedUpdate is guaranteed to be called once per timestep as opposed to once per frame, which means it may be called zero, one, or multiple times per frame while LateUpdate is guaranteed to be called exactly once per frame.

So if 2 seconds have passed since the last frame and your fixed timestep is 0.05, Unity will perform 4 back to back calls to FixedUpdate() during that frame. If 0.01 seconds have passed since the last frame, Unity won't call FixedUpdate that frame and will just accumulate the amount of time passed. You can easily replicate this behavior anywhere, this is pseudocode for what Obi does:

Code:
void LateUpdate()
{
   // accumulate time passed since last frame
   accum += Time.deltaTime;

   // while more than 1 timestep has passed, advance a timestep and subtract it from
   // the accumulator:
   while (accum >= Time.fixedDeltaTime)
   {
       InternalObiUpdate(Time.fixedDeltaTime);
       accum -= Time.fixedDeltaTime;
   }
}

If you're curious about what fixed timestepping means and how it's actually implemented in physics engines, I can recommend this timeless (no pun intended) classic:
https://gafferongames.com/post/fix_your_timestep/



It entirely depends on your script execution order.

kind regards,

Yes, you're 100% correct. I've read the exact article you posted but somehow I totally forgot it when I thought about Obi physics   Lengua

I was getting confused because I set a script's execution order to 10 and it still gets overridden by ObiBone. And it turns out that ObiBone has a default execution order of 100...



RE: (7.0) Still confused about how Obi physics updates in 7.0 - josemendez - 07-05-2024

(07-05-2024, 11:32 AM)kodra Wrote: I was getting confused because I set a script's execution order to 10 and it still gets overridden by ObiBone. And it turns out that ObiBone has a default execution order of 100...[/font][/size][/color]

This is because ObiBone must execute after ObiSolver, as it needs to be synchronized both to animation and simulation. You can still set your own components to execute after ObiBone if you need to.


RE: (7.0) Still confused about how Obi physics updates in 7.0 - kodra - 07-05-2024

(07-05-2024, 12:50 PM)josemendez Wrote: This is because ObiBone must execute after ObiSolver, as it needs to be synchronized both to animation and simulation. You can still set your own components to execute after ObiBone if you need to.

Yeah things seem to work fine when I set my script's execution order to 101. Thank very much for your answers!