Time.unscaledDeltaTime wrong values?

Hello,

When there’s a transition between scenes, I’m using white loading screen that fades in, load the level, and fades out.

My problem is that sometimes, the new scene opens a popup that pauses the game (Time.timeScale = 0). I’m fading out the loading screen with Time.deltaTime. You can see the problem.

I figured I would use Time.unscaledDeltaTime, but I get really weird results.

if I put this at the top of the Update method for my white loading screen:

Debug.Log("Time.frameCount: " + Time.frameCount + Environment.NewLine + 
		"Time.timeScale: " + Time.timeScale + Environment.NewLine + 
		"Time.deltaTime: " + Time.deltaTime+ Environment.NewLine + 
		"Time.unscaledDeltaTime: " + Time.unscaledDeltaTime+ Environment.NewLine);

I see some totally reasonable:

Time.frameCount: 391
Time.timeScale: 1
Time.deltaTime: 0.01656673
Time.unscaledDeltaTime: 0.01656673

But other times…

Time.frameCount: 396
Time.timeScale: 1
Time.deltaTime: 0.02
Time.unscaledDeltaTime: 0.2051583

Time.frameCount: 397
Time.timeScale: 1
Time.deltaTime: 0.3333333
Time.unscaledDeltaTime: 5.526389

Because of that, there is not fade out. It’s completely white one second, and then becomes instantly transparent.

This happens even when there are no manipulations at all of Time.timeScale… What is happening? It sucks that you can’t rely on it at all :frowning:

It is perfect reliable. Your unscaledDeltaTime just tells use that since the last frame 5.5 seconds have passed. Time.deltaTime is limited to 1/3 as this is the max allowed timestep. unscaledDeltaTime on the other hand returns the true delta. No frame has been rendered during that last 5.5 seconds. Your game was frozen during that time. Is it possible that you called Application.LoadLevel in frame 396?

LoadLevel is a blocking call. That’s why, when you have the pro version, you additionally have LoadLevelAsync which loads the level in the background.

edit
Some time ago i’ve written a fade-script for scene changes:

You simply need to fade out before you load your new level. While the level is loading you can’t do anything.