- Home /
Time.timeSinceLevelLoad does not reset
Hi,
in my game I'm trying to determine how much time has passed since the start of the level. Time.timeSinceLevelLoad
seemed to be the perfect built-in candidate for this. However, when tried using it, it simply did not reset at the loading of the level!
As this seems to be a pretty basic feature, I'm wondering if any of the below is causing this behaviour:
- I'm in Editor (that is, not a build)
- I'm reloading the same scene, not a different one
- I'm using additive scenes and there is a secondary scene that never gets unloaded (but it's not the active scene)
I suspect that the reason is this last one, that if not all the scenes are changed, the timer isn't reset, but I was wondering: does someone know what exactly causes this behaviour? Is this a bug in Unity?
UPDATE: I've made a minimal project to test the issue, and it is certainly present (see attachment). Additionally, I tested that it does not happen if the scene is just normally reloaded.
BTW, I'm on Unity 2018.2.0f2.
(Note: I don't need help in a workaround, I've already set up my own counter for this purpose that works perfectly. I would just like to know what is going on exactly, and possibly document an unusual/buggy behaviour of the Unity API).
so by reloading the same scene you mean loading ot an additionally you load all other necessary scenes actively again?
would otherwise not make much sense that you said there's a secondary scene that's never unloaded. in that case it will be.
By reloading I mean that I unload the scene ( Scene$$anonymous$$anager.UnloadSceneAsync()
), then load it again ( Scene$$anonymous$$anager.LoadSceneAsync()
), and set it as active scene. $$anonymous$$eanwhile there is a secondary scene that is untouched.
Answer by tormentoarmagedoom · Jul 30, 2018 at 10:12 AM
Good day.
As Unity manual says "This is the time in seconds since the last level has been loaded." I can think that you need to completly unload the levels and reload agan to reset the timer... I'm 95% sure its caused because you have opther scenes "pseudoloaded".
Bye
Then maybe you need to cahnage the way you take the time. RUN AWAY FROM PROBLEMS! :D If the timer does not reset, you need to create your own timer. store the time.time when you commence the level ina float variable called StartTime, and then everytime you need to know the time just need to
Actualtime = Time.time - StartTime
Bye again!
Hello!
Yes, I also think it is related to not unloading all the scenes, however, the second scene cannot be unloaded, because it is a manager scene used for persisting objects. In Unity 5 it was recommended to not use DontDestroyOnLoad()
anymore, ins$$anonymous$$d use a manager scene for that which is never unloaded. So I followed this recommendation, and in general it works great, a lot better than DontDestroyOnLoad()
, except now I've run into this issue.
There are various workarounds to this problem, but I want to really understand what is going on, and if this is a bug (BTW, I submitted a bug report for it, although I don't have high hopes that anything will be done about it).
Thank you for the suggestion, actually I did something similar even before posting the question. But as I said, I do not need a workaround for this problem, I want to understand, to know if I'm doing something wrong, or if this is a bug.
Your answer
![](https://koobas.hobune.stream/wayback/20220612171730im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
timer that can be reset 1 Answer
Timer not working as expected. 1 Answer
Reset speed after a specified time 1 Answer
Help With Simple Rotation 4 Answers