Time.deltaTime != unity_DeltaTime.x

When I run the following code in Unity 2022.2.13 (HDRP) on Windows I see that Time.deltaTime and the global shader variable unity_DeltaTime.x are not equal.

using UnityEngine;

public class DeltaTimeIssueTest : MonoBehaviour
{
    void Update()
    {
        float shaderDeltatime = Shader.GetGlobalVector( "unity_DeltaTime" ).x;
        Debug.Log( Time.deltaTime + " == " + shaderDeltatime );
    }
}

Can anyone reproduce this?

You showed code, but what actual number differences are you seeing?

Time.deltaTime is constantly being adjusted by the main loop. It is set to be equal to Time.fixedDeltaTime for the FixedUpdate phase, and back to a delta since last Update for the Update phase, which can be different for every frame since frames take different amount of time. It would seem like the time between Update and the time between shader loops would be the same, but I bet there’s a bunch of reasons they’d be a little different; they’re almost different computers after all.

0.02 == 0.0351838
0.02 == 0.0351838
0.0178645 == 0.0351838
0.0164728 == 0.0351838
0.0123308 == 0.0351838
0.0168116 == 0.0351838
0.0169292 == 0.0351838
0.015754 == 0.0351838
0.0189853 == 0.0351838
0.0161101 == 0.0351838

I’m not surprised that the shader system has a fixed dT, to be honest, but 28.4 FPS is a bit strange. I would’ve expected it to be in line with the target FPS or the vertical sync.

If you need the shader animation to be synchronous with the movements of game objects, you’ll probably want to pass in a position parameter yourself.

I have been relying on unity_DeltaTime for my custom compute shader particle systems for a while, and I do think Time.deltaTime and unity_DeltaTime.x used to be in sync when dispatching from the Update loop. This is also what I would expect from reading the documentation. As a workaround I just upload my own delta time, as you suggest.

Before I report this as a bug it would be great to see if others can reproduce it too.

Bug reported. Case IN-37921.

1 Like