Blog post: FixedUpdate, FixedTimestep, Maximum Allowed Timestep - What you thought you knew.

FixedUpdate and FixedTimeStep are concepts common not only in Unity but other physics engines and game engines. Most people have no idea how those work, lack of documentation and examples, and people who “really” know how it works and want to share their knowledge are very few.

It took a while to write and edit the video (linked in the text for those who prefer listening), but it was worth it. If you have just a little hint of doubt, I suggest you read it and check.

I normally write about programming good practices, general industry opinion and efficiency and graphics.
Share to anybody who tell you they know and they don’t , I’ve found so many of those…
Let me know if it was useful.

1 Like

Your blog seems to be well made. It’s great to have more people trying to communicate some of the basics concepts. There’s not a single way how something should / can be teached to people. Everybody learns different depending on their pre knowledge so having the same thing explained in different ways will help so more people finally get a hold on it.

I glanced over the blog and found a slight error. You said that fixedDeltaTime returns deltaTime when used from Update. That’s not true. fixedDeltaTime is a setting and as you said perviously doesn’t change unless you change it manually. What you said is true for deltaTime which returns the value of fixedDeltaTime when used from inside FixedUpdate. That’s why Unity even recommends when you want to make things framerate independent just always use deltaTime. It will return the right value depending on from where you use it.

A long long time ago I made this visualization (back then it was a Unity WebPlayer build ^^) which may help to understand how and when FixedUpdate is actually called depending on the framerate and fixed update rate. It’s a naive straight forward simulation. It has no random jitter like the real world, therefore it can easily run backwards.

I’ve also created the CustomFixedUpdate class which works pretty much the same as Unity’s own FixedUpdate loop but allows you to implement as many “fixed” callbacks as you want. Studying this class may give more insight how the mechanic works in terms of code.

Many people recently who have heard of deltaTime often use it in places where it makes no sense. This shows that a huge part of people haven’t even understood the concept of deltaTime and why and where we use it. I’ve seen code like

rb.velocity = someValue * Time.deltaTime;

Which obviously makes no sense, even when executed in Update. DeltaTime is only needed for values should be changed over time. It’s generally just converting a value that is defined in units per second into the required units per frame to achieve the desired units per second. The mathematical concept is actually trivial, but many seem to struggle with it.

1 Like

Thanks a lot for your comments and links, it is awesome!. About this error you found, well, sometimes I had to use DeltaTime in an area of code that needed fixedDelta and it was problematic. It is confusing that it returns different values depending on where you call it from. I don’t think stuff should be made to avoid problems from developers not knowing what they are doing. I think it’s the other way around, things should return what they should return and people should know what they are doing and study if they don’t understand… but clearly the documentation doesn’t help that much. :slight_smile:

Well. I just tried to explain it anyway. That’s my view… haha.

Cheers!