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 ewanko08 · Jun 04, 2012 at 09:00 PM · sceneimage

preloading many images before displaying scene

I have to load lots of images using WWW to be used as textures for my scene.

I have tried doing it through awake() and start() but everytime the scene displays, the images appear one by one, maybe it is still downloading the images while the scene has already been displayed. What I want to do is to preload all the images, before starting to display the scene.

How do I go about this? Maybe displaying a loading screen before loading the game scene.

Maybe someone can give a sample javascript to do this. thanks!

UPDATE: Adding codes
I have implemented a loading scene to download all images but it still takes awhile before the textures show up in the scene. The "loading scene" has a script that downloads all images to be used in the games. The "game scene" has many groups of panels that each has a LoadImage script attached to it. LoadImage script access static array in ImageHolder that has been loaded before hand.

Loading Scene:
ImageHolder script attached to main camera:

  function Start() {
         GetInstance();
         LoadImages();
  }

 private function GetInstance() {
     if(!Instance) {
         Instance = GameObject.FindObjectOfType(typeof(ImageHolder));
         }
 }

 private function LoadImages() {
     var panel_www = new WWW("web-service-url-for-all-images");
     yield panel_www; //wait to finish    

     var parsed = JSONParse.JSONParse(panel_www.text);
     var store_array = parsed["result"];        

     for(i=0; i<store_array.length; i++) {
         img_url = store_array[i]["image"];
         if(Instance.img_array[img_url] == null) { //if image has not been downloaded in cache 
             www = new WWW (img_url);        

         // Wait for download to complete
             yield www;                

             Instance.img_array[img_url] = www.texture;
         }
     }    
     Application.LoadLevel(2);
 }



Game scene:
LoadImage attached to group of planes.

 function Start() {
     yield StartCoroutine("loadStores");
 }
 
 function loadStores() {
     //store images
     var parts_img = new Array(17); //16 panels + 1 because index 0 is not used
     
     var panel_www = new WWW("web-service-url-for-each-panelgroup");
     
     yield panel_www; //wait to finish
     
     var parsed = JSONParse.JSONParse(panel_www.text);
     var store_array = parsed["result"];
     
     for(i=0; i<store_array.length; i++) {
         var part_number = parseInt(store_array[i]["part_number"]);
         parts_img[part_number] = store_array[i]["image"];
     }
     
     //store image parts
     var store_panel = transform.Find('Panel');
     var name;
         for (var child : Transform in store_panel)
         {
             name = parseInt(child.name);
             
             if(parts_img[name] == null) {
                 continue;
             }
             
             img_url = parts_img[name];
             
             // assign texture
             child.renderer.material.mainTexture = ImageHolder.Instance.img_array[img_url];
         }
 }
Comment
Add comment · Show 2
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 Wolfram · Jun 04, 2012 at 11:07 PM 0
Share

The reason why this happens is that WWW returns immediately and does its work in the background. So if you want to wait for it, you'll need a yield for each WWW call/creation, or check .isDone. See http://unity3d.com/support/documentation/ScriptReference/WWW.html and of course Berenger's answer.

avatar image ewanko08 · Jun 06, 2012 at 10:59 PM 0
Share

I am yielding each WWW calls.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Berenger · Jun 04, 2012 at 09:02 PM

Display a loading screen (OnGUI, GUITexture, whatever), pause the game (Time.timeScale = 0) and then load the pictures. Inside a loop, create the WWW and yield it, until all the pictures are loaded. The hide the loading screen, reset timeScale to 1 and on you go.

Comment
Add comment · Show 3 · 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 ewanko08 · Jun 06, 2012 at 11:02 PM 0
Share

I created a loading scene, and downloaded all images to be used while in this loading scene into a static class. Which is great. But, after calling LoadLevel to load the next scene, the textures in the planes (where the downloaded images are supposed to go) show up late. The scene is already show (including all characters) but the texture would only load up after a while. I am setting all textures in Start(). I have also tried moving it to Awake() and still no luck. If i'm not wrong, all Start() and Awake() methods must be finished first before calling the first Update() right?

By the way, the script that assigns the downloaded textures into planes are assigned to multiple objects. So they could all be running at the same time using just one static class that holds reference to the downloaded images.

avatar image Berenger · Jun 07, 2012 at 12:23 AM 0
Share

If the texture are correctly downloaded, the should be displayed the very frame you assign them, or the one after tops. Something is going on here, could you show us some code ?

avatar image ewanko08 · Jun 07, 2012 at 07:43 PM 0
Share

I added code in my post. I removed some of the details.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do i check if correct image is dragged in the panel?? 0 Answers

Load level after Image Sequence 0 Answers

Changing something in another scene by answering correctly 1 Answer

changing image format when building scene assetbundle 0 Answers

Making an image appear from a different script 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