Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Harinezumi · Jul 28, 2018 at 06:41 PM · timereset

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).

timesincelevelstarttest.zip (24.5 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Jul 29, 2018 at 12:58 PM 0
Share

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.

avatar image Harinezumi hexagonius · Jul 29, 2018 at 02:31 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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!

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Harinezumi · Jul 30, 2018 at 10:42 AM 0
Share

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).

avatar image tormentoarmagedoom Harinezumi · Jul 30, 2018 at 11:15 AM 0
Share

Extended answer

avatar image Harinezumi tormentoarmagedoom · Jul 30, 2018 at 11:22 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

89 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Resetting Time after Game Reload in iOS 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges