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 Sarcoex · Sep 30, 2013 at 11:17 PM · texturedeltatimemoviesequence

Time.deltaTime or Time.fixedDeltaTime for animated textures, such as a movie without sound (sequenced textures)

What is the best choice? with Time.deltaTime I sometimes get some "timeskips" when adding the value to a variable, in the Update():

 currentMS += Time.deltaTime * 1000;

The init value is 0 (int), but when adding the currentMS = Time.deltaTime * 1000 (milliseconds), it sometimes skips and adds a high number, it can best be descriped as similar to a frameskip or a fps drop. Can I use FixedUpdate() with Time.fixedDeltaTime instead?

The code is based on images (frames) extracted from a movie file. The frames are then inserted into an array. And the code switches frames based on fpms (frames per millisecond).

 m = frames per millisecond
 f = frames per second
 
 m =(1/f)*1000

My current code is here:

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class SVideo : MonoBehaviour {
     
     public Texture2D[] frames;
     public bool isPlaying = false;
     public int fps = 1;
     
     private int ms = 1000;    
     private float currentMS = 0f;
     private int i = 0;
     
     // Use this for initialization
     void Start () {
         ms = (int) ((1f / (float) fps) * 1000f);
         Debug.Log("FP-MS: " + ms);
     }
     
     // Update is called once per frame
     void Update () {
         if (isPlaying) {
             currentMS += Time.deltaTime * 1000;
             Debug.Log("Current MS: " + currentMS);
             
             if (currentMS >= ms) {
                 currentMS = 0f;
                 
                 if (i >= frames.Length-1) {
                     i = 0;
                 }
                 
                 this.renderer.material.mainTexture =(Texture) frames[i];
                 i++;
             }
         }
     }
     
     void OnDrawGizmos() {
         Gizmos.DrawIcon(this.transform.position, "SVideo.png", true);
     }
     
     public void Play() {
         isPlaying = true;
         audio.Play();
     }
 }
 
Comment
Add comment · Show 1
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 Sarcoex · Oct 01, 2013 at 12:01 AM 0
Share

Just thoroughly re-read the Time.deltaTime reference. And it states this:

When called from inside $$anonymous$$onoBehaviour's FixedUpdate, returns the fixed framerate delta time.

So my guess is that it's best to use FixedUpdate() with Time.deltaTime, is my assumption correct?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Oct 01, 2013 at 12:10 AM

You can use either one. FixedUpdate() and Time.fixedDeltaTime or Time.deltaTime will likely give you a bit more regular frame rate. With that said, I do see one bug in your code that might account for what you are seeing. On line 27/28 you have this:

 if (currentMS >= ms) {
     currentMS = 0f; 

A better solution will be:

 if (currentMS >= ms) {
     currentMS -= ms;

Also here is another implementation for comparison. It uses Update() also, so you check to see if it is smoother.

http://answers.unity3d.com/questions/392517/introduction-movie.html

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

14 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

Related Questions

Unity Movie Texture Audio Black Screen 1 Answer

MovieTexture Quality 0 Answers

Assigning UV Map to model at runtime 0 Answers

Swap Custom Cursor for Animated Movie Texture or Sprite Sheet? 1 Answer

Image Sequence Loop 0 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