So what's the deal with FixedUpdate?

Hi
Here’s one thing I don’t understand: why should I even bother with the Delta Time in my Update Functions, when I can just simply put everything into FixedUpdate?

The way http://docs.unity3d.com/ distinquishes between these updates is something along the lines:
Update - gets called on every frame, but the time between each call may vary.
FixedUpdate - gets called pn every frame, but the time between each call is constant.

Well, that’s basically the same thing, except the second one is accurate!
What am I missing here?

If you’re happy with the results when you put your code in FixedUpdate then you can leave it like that - it is up to you. Some things don’t work so well there though, such as button press detection.

Update is called for every rendered frame; but FixedUpdate may or may not get called, and it may get called multiple times between renders. Also, it’s not true to say that the real-world time interval between FixedUpdates is constant - it is not, they are called at a consistent rate but not at exactly the right times. Usually this doesn’t matter. The elapsed game time reported between calls will always be the same, in any case.

I’ll explain in more detail…

Unity’s main concern is to run an Update/Render loop as fast as possible, subject to some throttling - e.g. no faster than the monitor refresh rate. This loop includes pretty much everything other than FixedUpdate and the internal physics system - so Update, LateUpdate, coroutines, and so on. Time.deltaTime is set to however long the previous loop took to execute, including both updating and rendering.

In addition, just before running the Update function each time, it runs however many fixed update cycles are necessary to preserve a regular rate of fixed updates. These fixed update cycles include calling your FixedUpdate methods, and advancing the internal physics. If the Update/Render cycle is efficient enough then sometimes there won’t be any fixed update cycles at all; if the Update/Render cycle is slow then on some/all frames the fixed update cycle will run multiple times.

It’s a bit like this:

while (true)
{
    float frameStartTime = Time.realTimeSinceStartup;
    float deltaTime = frameStartTime - Time.time;

    // Run fixed-length updates until Time.fixedTime catches up with the frame start time
    while (Time.fixedTime + Time.fixedDeltaTime < frameStartTime)
    {
        Time.fixedTime += Time.fixedDeltaTime;

        // Unity lies about these during FixedUpdate
        Time.time = Time.fixedTime;
        Time.deltaTime = Time.fixedDeltaTime;

        FixedUpdate();
        AdvancePhysics();
    }

    // Set these to non-fixed values again for Update()
    Time.time = frameStartTime;
    Time.deltaTime = deltaTime;

    Update();
    LateUpdate();

    Render();
}

FixedUpdate should be used instead of Update when dealing with Rigidbody. For example when adding a force to a rigidbody, you have to apply the force every fixed frame inside FixedUpdate instead of every frame inside Update.