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 tetigi · Apr 17, 2014 at 12:57 AM · androidcoroutinetimetimestep

Timings and synchronization difference after build

Hi all,

I've been mucking around trying to make my first game in Unity, and I've encountered some problems with timings differences between preview and build versions of the game.

I'm trying to make a simple guitar-hero style clone, except instead of having many notes there is only one note for a drum. The drum is played in a rhythm to a song.

To accomplish this I have abstracted the idea of movement to beats per minute - on frame Update, I try to get the time elapsed since the last frame, and move all notes on the trail forwards by that many beats. The code looks something like this:

 // In NoteTrail.cs
 void Update () {
     float bps = bpm / 60.0f;
     float secsSinceLastFrame = Time.deltaTime;
     float beatsToMove = bps * secsSinceLastFrame;
 
     foreach (Note note in notesOnTrail) {
         note.Advance(beatsToMove);
     }
 }

 // In Note.cs
 public void Advance (float beats) {
     beatsElapsed += beats;
     UpdatePosition(beats * NoteTrail.PIXELS_PER_BEAT);
 }
 
 public void UpdatePosition(float dist) {
     float currentY = transform.position.y;
     transform.position = new Vector3(0.45f, currentY - dist, 0.5f);
 }

This seems to work well on my computer - the song is 165 bpm, so in my code I play the start of the song on load, wait n beats, then start the trail moving.

However, as soon as I build the project, the timings go really weird - the notes appear to be moving faster, and other sound triggers appear laggy (these are triggered as coroutines). This occurs both when building locally (for mac), and when building as an app for Android. Again, I do not get this problem when running the game in the preview.

What is it about the process of building that could cause these discrepancies? I had hoped that by using Time.deltaTime this would not be a problem.

Any kind of advice on timings would be helpful :)

Luke

(I can provide more context on how the code works if needed!)

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

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Complex Mecanim recording in a single game update? 1 Answer

How to check if input was made x seconds/frames ago? 0 Answers

stop game for 1 second 2 Answers

how to chick the time that passed when the game was closed 2 Answers

Extreme amounts of processing crash android build? 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