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 Balthatczar · Jan 17, 2014 at 07:40 PM · updatetexture2dyielddownloadienumerator

downloading data via coroutine in Update()

I've written a coroutine that fetches a text file with a number of url's in them to images and then goes about downloading those images and puts them in a texture2d array. This works fine if i call on the coroutine in Start(), however what i want the coroutine to do is download the first image in the list (of urls) in Start() and then depending on user interaction i want to download each next image in the list, this user interaction is registered in Update(), but if the coroutine is called upon in Update() nothing happens, no data is transferred at all... Could anyone help me out here? I'd be grateful for it.

Its quite a lot of code, but lots of it unrelated to the problem in this function. All the rest is for creating puzzle tiles out of a single image so i left that all out. Anyway i just tested this as written down below and again it works if called upon in Start(), but not Update().

So i want to call on this coroutine in update, so that i can download a new image in the list based on user interaction.

So here it goes:

    public IEnumerator loadPuzzleTiles_index(int puzzelNR) 
            {
             
               // download list url's puzzle images
                 
               yield return puzzleTiles_index_www;
         
               // download image in list
         
               if (puzzleTiles_index_www.isDone)
               {    
                 puzzleTiles_indexList = puzzleTiles_index_www.text;
                 puzzleTiles_indexArr = puzzleTiles_indexList.Split('\n');
                 puzzleTiles_puzzleIndex_www = new WWW[puzzleTiles_indexArr.Length];
                 puzzleTiles_puzzleIndex_texture = new Texture2D[1];
         
                 puzzleTiles_puzzleIndex_texture[0] = new Texture2D(832,664,TextureFormat.ARGB32,false);
         
                 puzzleTiles_puzzleIndex_www[puzzelNR] = new WWW(puzzleTiles_indexArr[puzzelNR]);            
                 yield return puzzleTiles_puzzleIndex_www[puzzelNR];
         
                 if (puzzleTiles_puzzleIndex_www[puzzelNR].isDone)
                 {
                puzzleTiles_puzzleIndex_texture[0]  = puzzleTiles_puzzleIndex_www[puzzelNR].texture;
                 }
         
                }
         
              }
 
 
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 robertbu · Jan 17, 2014 at 07:51 PM 0
Share

Coroutines are not my strong point since I only use them in pretty standard ways, but Line 6 concerns me. What happens if you change line 6 to:

 while (!puzzleTiles_index_www.isDone) {
     yield return null;
 }

And make sure you are only calling this coroutine once from Update().

avatar image Balthatczar · Jan 17, 2014 at 09:23 PM 0
Share

Excellent, looks like this is working! Thank you so much. I'd like to make it possible that the application not almost completely freezes more or less when the data is being downloaded. Is that doable you think?

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

18 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

Related Questions

coroutine not downloading data in Update() 0 Answers

Figuring out Coroutines 3 Answers

Instantiate an object as soon as another object is destroyed 2 Answers

How can I use a yeild during an udate? 1 Answer

Calling IEnumerator function with variables does not do anything 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