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 homer_3 · Jun 26, 2016 at 12:26 AM · time

Time not accurate?

I'm working on a music game, so I need to be able to accurately sync the music with what's going on in the game. And it all works as long as nothing too taxing is going on in the scene. But there are times when Unity's time seems to slow down when the frame rate can't keep up. For example, if I play a 3.5 minute song (210 seconds long), if I log the current Unity time and start a separate stop watch when the song starts, when it ends, the stop watch will correctly show 3.5 minutes have passed, but based on the Unity logs, only 190 seconds or so will have passed.

I'm guessing Unity is limiting the max delta time allowed between frames? Is there a way to turn that off so I can keep an accurate time?

Comment
Add comment · Show 3
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 jgodfrey · Jun 26, 2016 at 01:46 AM 0
Share

What time resolution do you need (seconds, milliseconds, ??). Depending on your requirements, there are other Time members that might suit you. Also, maybe there's something wrong in your code? If you can paste the relevant code here, you'll likely get some more targeted input.

avatar image tanoshimi · Jun 26, 2016 at 02:38 PM -1
Share

A 3.5 $$anonymous$$ute song is 210 seconds, so both your recorded ti$$anonymous$$gs are miles out. Please show the code you're using - there's definitely a mistake somewhere to be getting errors of that magnitude.

avatar image homer_3 tanoshimi · Jun 26, 2016 at 03:26 PM 0
Share

Yea, yea. It was still 190 seconds vs 210 seconds.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Plattinator · Jun 26, 2016 at 06:02 AM

Not sure about the Unity time going slower than real-time, but if you're using an AudioSource to play your music, you can get the current playback time of the AudioSource through AudioSource.time. That should allow you to get the exact time for where you're at in the music to sync up with the game.

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 homer_3 · Jun 26, 2016 at 01:43 PM 0
Share

I've been using this where I can to combat the problem, but objects still move based on Time.deltaTime. AudioSource doesn't have a deltaTime. Though, maybe I could try calculating my own based on the AudioSource's time.

avatar image
0

Answer by Mindmapfreak · Jun 26, 2016 at 09:41 PM

You could try to use the Stopwatch-class and see if it is more accurate in your case.

 using UnityEngine;
 using System.Collections;
 using System;
 using System.Diagnostics;
 using Debug = UnityEngine.Debug;
 
 public class StopwatchTest : MonoBehaviour {
     private Stopwatch stopwatch;
     // Use this for initialization
     void Start () {
         this.stopwatch = new Stopwatch();
         this.stopwatch.Start();
         if(Stopwatch.IsHighResolution)
         {
             Debug.Log("The stopwatch is high resolution");
         }
     }
     
     // Update is called once per frame
     void Update () {
         float elapsedSeconds = ((float)this.stopwatch.ElapsedMilliseconds)/1000.0f;
         Debug.Log(Time.time+" vs "+ elapsedSeconds);
     }
 }
Comment
Add comment · 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

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

46 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

Related Questions

Problem Min and Max Time 1 Answer

fuel compsumation 0 Answers

Force mode and delta timing 1 Answer

How can I match up some code and an animation keyframe 0 Answers

When to use Time.deltaTime? 3 Answers


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