X axis is each Update sample point
Y axis is Time.deltaTime
5.6.1f1
If anybody is reading/watching this thread would you mind creating a blank new project and a blank scene with this script. What kind of Time.deltaTime variation do you see (both in the editor and when building an executable).
using UnityEngine;
using System.Collections.Generic;
public class FPS : MonoBehaviour
{
private List<float> listDeltaTime = new List<float>();
private const int pixelWidth = 256; //for texture2D
private const int pixelHeight = 128; //for texture2D
private Texture2D texture2D;
private const float deltaTimeMax = 0.05f; //for texture2D
private static readonly Color colorDarkGrey = new Color(0.3f, 0.3f, 0.3f);
private void Awake()
{
DontDestroyOnLoad(gameObject);
for (int i = 0; i < pixelWidth; i++)
{
listDeltaTime.Add(0.01f);
}
texture2D = new Texture2D(pixelWidth, pixelHeight);
texture2D.filterMode = FilterMode.Point;
}
private void Update()
{
listDeltaTime.RemoveAt(0);
listDeltaTime.Add(Time.deltaTime);
RefreshTexture2D();
}
private void OnGUI()
{
float deltaTimeAve = Average(listDeltaTime);
float deltaTimeMin = Mathf.Min(listDeltaTime.ToArray());
float deltaTimeMax = Mathf.Max(listDeltaTime.ToArray());
GUI.Label(new Rect(10f, 10f, 200f, 20f), "DeltaTime (Average) = " + (deltaTimeAve * 1000f).ToString("0.000") + "ms");
GUI.Label(new Rect(10f, 30, 200f, 20f), "FrameRate (Average) = " + (1f/ deltaTimeAve).ToString("0"));
GUI.Label(new Rect(10f, 50, 200f, 20f), "Time.deltaTime = " + (Time.deltaTime * 1000f).ToString("0.000") + "ms");
GUI.Label(new Rect(10f, 70f, 200f, 20f), "deltaTimeMin = " + (deltaTimeMin * 1000f).ToString("0.000") + "ms");
GUI.Label(new Rect(10f, 90f, 200f, 20f), "deltaTimeMax = " + (deltaTimeMax * 1000f).ToString("0.000") + "ms");
GUI.Label(new Rect(10f, 110f, 200f, 20f), "% Variation = " + ((deltaTimeMax/ deltaTimeMin -1f) * 100f).ToString("0.0") + "%");
GUI.DrawTexture(new Rect(0f, 200, Screen.width, texture2D.height*2), texture2D);
}
private void RefreshTexture2D()
{
Color[] pixels = texture2D.GetPixels();
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = Color.black;
}
texture2D.SetPixels(pixels);
float deltaTimeMin = Mathf.Min(listDeltaTime.ToArray());
float deltaTimeMax = Mathf.Max(listDeltaTime.ToArray());
int yMin = GetY(deltaTimeMin);
int yMax = GetY(deltaTimeMax);
for (int i = 0; i < pixelWidth; i++)
{
texture2D.SetPixel(i, yMin, colorDarkGrey);
texture2D.SetPixel(i, yMax, colorDarkGrey);
}
for (int i = 0; i < pixelWidth; i++)
{
int y = GetY(listDeltaTime[i]);
texture2D.SetPixel(i, y, Color.white);
}
texture2D.Apply(false);
}
private static int GetY(float deltaTimeIn)
{
return Mathf.Clamp(Mathf.RoundToInt(deltaTimeIn / deltaTimeMax * pixelHeight), 0, pixelHeight - 1);
}
private static float Average(List<float> listFloatIn)
{
float average = 0f;
for(int i = 0; i < listFloatIn.Count; i++)
{
average += listFloatIn[i];
}
average = average / listFloatIn.Count;
return average;
}
}
I typically see 50-100% Time.DeltaTime variation (jitter) in the .exe build (Windows). What do you guys see?
Any idea how to fix this Unity jitter issue? Still unsure why a blank project with Vsync enabled sees 100% Time.deltaTime variation that causes all this jitter.