Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 gumboots · Jun 24, 2015 at 12:24 AM · bug-perhapsframerateimportingtime.timeprocessing

Heavy Processing Messes With Time.time

Hi there,

I begin my game by starting a coroutine:

 void Start() {
     StartCoroutine(ImportAssets());
 }

In here, I wait for two seconds, and then save the current time:

 IEnumerator ImportAssets() {
     yield return new WaitForSeconds(2);
     
     startTime = Time.time;
 }

Then, in my Update function I test to see if a character needs importing, if it does I disable the script while it imports. (Ignore the first if statement for a moment.)

 void Update() {
     if (itemsLoaded == total) {
         Helpers.Log(Time.time);
         Helpers.Log(startTime);
         Helpers.Log("Loaded in", Time.time - startTime);
 
         total = 0;
 
         enabled = false;
     }
 
     if (readyCharacters.Count > 0) {
         enabled = false;
 
         StartCoroutine(ImportCharacterObjects(readyCharacters[0]));
     }
 }

Importing the characters takes a lot of work, and actually holds a few frames for a couple of seconds. Once all the characters are imported, that if statement runs fine, however Time.time is definitely incorrect.

  • startTime logs out at ~2.002099 (Which is correct)

  • Time.time logs out at ~4.877523 (Which is incorrect, using a stop watch I measure at least 8 seconds)

  • As such, Loaded in logs out at ~2.875424, which is obviously also incorrect.

I've had the thought that maybe locking up frames in the game throws out its time counter? Otherwise I'd love to find out what's going wrong, as I need an accurate timer for this importing process.

Thanks in advance!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by zach-r-d · Jun 24, 2015 at 02:20 AM

Time.time is not "real" time; it's affected by things like Time.timeScale, and whether the game is paused. It thus seems probable that it is also affected by Time.maximumDeltaTime (which exists to prevent well of despair scenarios), meaning that frames longer than the maximum delta time get added as if they took the maximum time amount rather than the real, higher amount.

For the desired functionality, try experimenting with some of the other properties available in Time, such as Time.realtimeSinceStartup or Time.unscaledTime. If those don't work, I would recommend using the System.Diagnostics.Stopwatch class.

Comment
Add comment · Show 1 · 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 gumboots · Jun 24, 2015 at 02:29 AM 1
Share

$$anonymous$$akes sense!

I've switched to use Time.realtimeSinceStartup, however I also used a few *yield return null*s to split the loading so the game doesn't freeze anyway.

Thanks!

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

22 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

Related Questions

2D game performance keeps slowing tremendously when resolution is at 1080p (1920 x 1080) 1 Answer

Import Project from Asset store 6 Answers

How to create a framerate independent time delay in Update() without coroutines 1 Answer

Unity editor low frame rates and flashing while pressing keys 1 Answer

Why does my external monitor get x5 lower frame rate? 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