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 /
  • Help Room /
avatar image
0
Question by john-essy · Mar 18, 2019 at 02:02 PM · texture2dloading textures

Load a lot of images from server to app without the app freezing when applied! (500+ Images)

So i am currently developing an app for a national park in Africa and have currently hit a snag. I download the images to the users device if they do not exist locally to be used by the app. The problem is with my current approach.

I go through all the animals data and apply all of this to the animals page then also apply the image from local storage. When i do this the app freezes and currently on my PC it takes over 8 seconds to load the pictures into the sprite. Again remembering there are over 100 animals being loaded here.

How would you load all these images and remove the hang of the app? This is the code i use to load the images to sprites. My biggest concern here is that in the apps "Birds section" there are over 250 images

 Stopwatch timer = new Stopwatch(); 
         timer.Start();
 
         using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture("File:///"+Application.persistentDataPath + "/" + FilePath + ".jpg"))
         {
             yield return uwr.SendWebRequest();
 
             if (uwr.isNetworkError || uwr.isHttpError)
             {
                 UnityEngine.Debug.Log(uwr.error);
             }
             else
             {
                 //// Get downloaded asset bundle
                 var texture = DownloadHandlerTexture.GetContent(uwr);
                 var NewSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0), PixelsPerUnit, 0, spriteType);
                 UnityEngine.Debug.Log("NS:::::::::::::::::" + NewSprite);
                 onComplete(NewSprite);
                 timer.Stop();
                 TimeSpan timeTaken = timer.Elapsed;
                 UnityEngine.Debug.Log("Time Taken To Load Images " + timeTaken);
             }
         }


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 xxmariofer · Mar 18, 2019 at 02:53 PM 0
Share

you are calling that coroutine per image right? how are you starting the coroutine? all at the same time?

avatar image john-essy · Mar 19, 2019 at 01:54 PM 0
Share

Yes, I go through each entry in the class and start a coroutine for it like this. The method Download is just a container for the Coroutine.

 public void DownloadAllFiles()
     {
         foreach (var animal in mammalData.allSpecies)
         {
             foreach (var img in animal.ImageName)
             {
                 if (!File.Exists(Application.persistentDataPath + "/" + img + ".jpg"))
                 {
                     
                     Debug.Log("The File " + img + ".jpg did not exist on our machine, Start the download process from Firebase \n Full file location is  " + Application.persistentDataPath + "/" + img + ".jpg - If this is " +
                         "a Low res image make sure it is named the same it is on firebase to stop the needed for changes in the app control panel");
                     Download(img, animal.animalGroup.ToString());
                 }
             }
         }
 
         foreach (var animal in mammalData.multiSpecies)
         {
             foreach (var img in animal.subSpecies)
             {
                 foreach (var imgName in img.ImageName)
                 {
                     //Debug.Log("Data Path is :: " + Application.persistentDataPath + "/" + imgName + ".jpg");
                     if (!File.Exists(Application.persistentDataPath + "/" + imgName + ".jpg"))
                     {
                         Debug.Log("The File " + imgName + ".jpg did not exist on our machine, Start the download process from Firebase \n Full file location is  " + Application.persistentDataPath + "/" + imgName + ".jpg - If this is " +
                                                 "a Low res image make sure it is named the same it is on firebase to stop the needed for changes in the app control panel");
                         Download(imgName, animal.animalGroup.ToString());
                     }
                 }
             }
         }
     }
avatar image xxmariofer john-essy · Mar 19, 2019 at 02:00 PM 0
Share

can you try changing the var texture line in the corroutine for this and check if it getsany better?

 Texture myTexture = ((DownloadHandlerTexture)uwr.downloadHandler).texture;

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by john-essy · Mar 21, 2019 at 11:10 AM

I know im answering my own question here but i got some valuable help from unity forums. - Check here for the solution

Solution

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

207 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 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 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 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 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

Trying to create a freaking math clone. new learner and very low coding skills. Having trouble with setting the time limit for the process.Need Help? 1 Answer

SetPixels edge pixels 0 Answers

Unity seems to be in 2D, but I want it in 3D 1 Answer

Using bitmaps for Image-processing with Unity 1 Answer

LoadRawTextureData - how to use? 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