Time.deltaTime is "frozen" when game object is disabled
Hello
I noticed that if gameobject is disabled (setActive(false)) , then time delta seems to freeze. Basically it returns the time since the last frame is displayed and when the gameobject has entered the disabled mode. Whether I enable the object 1 sec or 10 seconds later, it is the same value returned.
Any idea why or how to get around that?
My use case is I am basically I am using the time delta to move the object and it seems to resume from when it was disabled and not (say 10 steps later)
Thank you
deltaTime is a static member of the Time class- it can't be different for each gameObject, since there is only 1 instance of it at any time. deltaTime is the time it took for the last frame of the game to complete.
If I understand what you are trying to do, you might try running your script on an empty that never gets disabled, and have a separate gameObject for the visual part that follows the empty and does get disabled. That way when you enable the visual it will pick up wherever the empty is at that point.
I guess you use Time.deltaTime in the Update() function of the script attached to the gameobject. When you disable it "Any scripts that you have attached to the GameObject will no longer have Update() called, for example." You probably want to just disable the $$anonymous$$eshRenderer component of the gameobject (GetComponent().enabled = false;)
Answer by hyperi0n · Jun 28, 2016 at 01:12 PM
I suppose the easiest way would be to create your own "deltaTime": At the end of a frame set
myDeltaTime = Time.time - lastUpdate;
lastUpdate = Time.time;
and then use this "fake" deltaTime in the places where you need to use this tracked "time-since-last-update-even-if-the-object-was-disabled". Would this work for you?
Answer by Xepherys · Jun 28, 2016 at 06:15 PM
You can always use Time.realtimeSinceStartup
instead - maybe at least when activating and deactivating an object? Or at least when reactivating an object, you could use it to find the time elapsed since disabling it with an appropriately set variable.
Thanks for the idea. I wanted to stick to delta time but your idea would work as well
Your answer

Follow this Question
Related Questions
Unity coroutine movement over time is not consistent/accurate? 1 Answer
how to simulate a hand using IMUs ? 0 Answers
[UNET] Problems with syncing Weapon rotation 0 Answers
Problem with figures 3d,Mistake with figures 3d 1 Answer
The error : No overload for method 'Clamps' takes 1 argument. 1 Answer