Frame skipping in an empty project

Hi,

I have created an empty project with a very simple script that just changes the background color every time Time.deltaTime is considerably longer than it was during the previous frame.
The script also enables VSync so deltaTime should stay relatively stable.

As the project is basically empty, I expected it to not skip any frames, especially as I have a beefy computer (5900X + RTX3080).

But every second or so, it skips a frame.

Am I doing anything wrong ?

Here is the script in case anyone is interested :

using UnityEngine;

public class FrameSkipTester : MonoBehaviour
{
    private float _previousDeltaTime = 0;
    private Camera _camera;

    private void Awake()
    {
        QualitySettings.vSyncCount = 1;

        _camera = GetComponent<Camera>();
        _camera.clearFlags = CameraClearFlags.SolidColor;
    }

    private void Update()
    {
        float deltaTime = Time.deltaTime;

        if (deltaTime > 1.5f * _previousDeltaTime)
            _camera.backgroundColor = Color.white;
        else if (deltaTime > 1.1f * _previousDeltaTime)
            _camera.backgroundColor = Color.red;
        else
            _camera.backgroundColor = Color.black;

        _previousDeltaTime = deltaTime;
    }
}

If it’s in the editor it means absolutely nothing. You can expect hitches there.

Otherwise if its in a build, start all performance investigations with the profiler.

Window → Analysis → Profiler

It is indeed ocurring in builds.
The profiler points to “DXGI.WaitOnSwapChain” as the cullprit when profilinq a build.
However, as this is an empty project, I really have no clue why this induces a frame skip…

Strangely, this happens more often than not. I mean the testing of an empty project that shows a behaviour that’s never observed in any real project. :wink:

Be sure to test with the latest patch release.

Then add Graphy to have an actual ingame framerate counter and a frametime diagram.

Consider that deltaTime with Vsync enabled will only ever be 0.01666 or 0.03333 and so forth. So the way you multiply is unlikely to give you a real indication, at most the screen should go white but never red.

I will try Graphy.

I also thought that with VSync, I would only get integer multiples of my screen frame time, however this is really not the case… Time.deltaTime fluctuates, which is really strange to me.

Edit : I tried Graphy and the problem stands.
image

PS : I am using 2022.3 LTS up to date. But I am seeing the behaviour on all the versions I tested.

We can’t see your profiler shot btw. :wink:
Regardless of that, these spikes are curious. I would also check for a graphics driver update just in case. Personally I prefer the “Studio” or “PRO” drivers as they are more stable.

I have edited my previous post to include the Profiler screenshot.

I have installed Studio drivers, they indeed seem more stable to me (the randomness of it all may just be tricking me though)

However the skipped frames and irregular deltaTimes are still present :
image

Has anyone tried to check an empty project on their machine ?

PS : I have tried with a VSync count of two and the problem still stands so I really don’t think this is a performance issue.
I think unity may be missing screen refreshes plain and simple…

You have tested on only one machine so far? If so, you can’t make that assessment yet. Try running this test on other machines, for all we know it could be a hiccup in your system perhaps caused by cooling or power or driver or background process issues.

There are so many variables and you’re the first to report such an issue, thus the likelihood that this is a localized issue is high unless confirmed by others or other systems. :wink: