Problem with Time.deltaTime

float elapsedTime = 0;

private void Update()
{
    elapsedTime += Time.deltaTime;
    Debug.Log(elapsedTime);
}

elapsedTime updates correctly when i first load the scene, when i reload the scene, elapsedTime stays at 0. i have no other code affecting this variable.

Debug.Log
before scene reload:

1.757754
UnityEngine.Debug:Log (object)
EnchantItemManager:Update () (at Assets/EnchantItemManager.cs:125)

1.774392
UnityEngine.Debug:Log (object)
EnchantItemManager:Update () (at Assets/EnchantItemManager.cs:125)

1.79111
UnityEngine.Debug:Log (object)
EnchantItemManager:Update () (at Assets/EnchantItemManager.cs:125)

1.807785
UnityEngine.Debug:Log (object)
EnchantItemManager:Update () (at Assets/EnchantItemManager.cs:125)

After scene reload:

0
UnityEngine.Debug:Log (object)
EnchantItemManager:Update () (at Assets/EnchantItemManager.cs:125)

Did you set Time.timeScale to 0?

2 Likes


whoops yup thats it. setting it to 1 worked. thanks, completely overlooked it :smile:

1 Like