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 Kuro13 · May 03, 2015 at 10:22 PM · spritespriterendererresources.loadmovietextureunloadunusedassets

Resources.Load have a bad performance

I'm trying to play a movie in Android by using SpriteRenderer because MovieTexture can't be used for Android. Basically, I convert the movie into images and load it as Sprite and assign it to a SpriteRenderer every frame. I put the images in Resources/Movie folder and use this code to load the Image. (Variable counter is what frame the movie currently playing)

 Sprite GetFrame(){
     Sprite newSprite = Resources.Load("Movie/picture" + counter.ToString("0000"), typeof(Sprite)) as Sprite;
     return newSprite;
 }

At the beginning, the movie play smoothly, but after 10 seconds or so the movie starting to lag. I try to unload the resource every 2 seconds using Resources.UnloadUnusedAssets(); but the problem still exist. Here is my full code for this.

 using UnityEngine;
 using System.Collections;
 
 public class CPlayButton : MonoBehaviour {
     private const int FPS = 24;
     private const int UNLOAD_TIME = 2;
 
     public SpriteRenderer movieTexture;
     
     private float SPF = 1f / FPS;
     private float UNLOAD_FRAME = 2 * FPS;
     private float timeCounter = 0;
     private int counter = 0;
     private int unloadCounter = 0;
     private bool isPlaying = false;
 
     // Use this for initialization
     void Start () {
         timeCounter = SPF;
     }
     
     // Update is called once per frame
     void FixedUpdate () {
         if (isPlaying) {
             if(timeCounter >= SPF){
                 counter++;
 
                 movieTexture.sprite = GetFrame();
                 timeCounter = timeCounter - SPF;
 
                 if(unloadCounter >= UNLOAD_FRAME){
                     Resources.UnloadUnusedAssets();
                     unloadCounter = 0;
                 }else{
                     unloadCounter++;
                 }
             }else{
                 timeCounter += Time.fixedDeltaTime;
             }
         }
     }
 
     Sprite GetFrame(){
         Sprite newSprite = Resources.Load("Movie/picture" + counter.ToString("0000"), typeof(Sprite)) as Sprite;
         return newSprite;
     }
 
     void OnMouseDown(){
         isPlaying = true;
     }
 }
 

Can somebody help me about this problem? Or anybody know a better way of doing this?

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 fafase · May 04, 2015 at 06:19 PM 0
Share

Best would be too load a certain amount of images before starting to play.

You could also try to run it all without unloading as it seems to correspond to the starting of the lagging.

$$anonymous$$aybe just nullify your images and let the GC do its job or call GC.Collect once you are done with the full movie.

Also, can't you just use Handheld class for playing movie?

avatar image fafase · May 04, 2015 at 06:21 PM 0
Share

Other idea, try to compare using Resources and placing your images in the data folder and using File.ReadAllBytes.

avatar image Kuro13 · May 05, 2015 at 03:28 PM 0
Share

i try to load certain amount of images in the beginning and load the rest while playing the loaded image, but when the loaded image already played, the new images not finish loaded. so the problem still same. i try the handheld already but the problem is handheld stop all process other than playing the movie. so i cant make other calculation while playing the movie. $$anonymous$$aybe the only choice is to use plugin as suggested by zeppike

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by siaran · May 03, 2015 at 10:27 PM

Try not loading a single frame each update. Instead, load all your frames into memory in Start() and loop through them in Update().

Or make an animation prefab for your animation and use that + the animator.

Comment
Add comment · Show 5 · 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 Kuro13 · May 04, 2015 at 10:16 AM 0
Share

Sorry not mention it in the question, but my movie is around 1 - 2 $$anonymous$$s long. So for 24 fps, there are around 2000 images. I tried load all the frames in the beginning but it load so long.

avatar image siaran · May 04, 2015 at 06:09 PM 0
Share

can't you store it as a movie ins$$anonymous$$d of a set of images? because you really shouldn't need to load/unload an image during an update...as you said it's not very fast...

avatar image Kuro13 · May 05, 2015 at 10:17 AM 0
Share

as I said in the question, I tried $$anonymous$$ovieTexture to open movie file, but it can't be used for Android. There is only fullscreen movie player using HandHeld for Android. But I want to process something while the movie playing and using HandHeld make my process stop. Or do you have other way to play movie file?

avatar image zeppike · May 05, 2015 at 10:21 AM 0
Share

Use the $$anonymous$$obile$$anonymous$$ovieTextures Asset is is 70 or so dollars, but it will save you a lot of time, performance and pain.

avatar image Kuro13 · May 05, 2015 at 10:30 AM 0
Share

Actually, I never buy anything in asset store. Are you sure that plugin will work? I don't know how to check a plugin is really work or not without buy it first.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Resources.Load sprite returning null 2 Answers

Change sprite in a sprite renderer with an animation 0 Answers

Assign multiple sprites to a renderer, or assign multiple renderers to single object 1 Answer

Change sprite's color without making an extra drawcall 0 Answers

Cut holes in sprite using other sprites 2 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