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 /
avatar image
0
Question by KW90 · Jul 17, 2017 at 08:49 PM · coroutinewww.loadimageintotexture

Why do multiple Unity coroutines speed up www image loading?

I googled my way through lots of questions all day but I didn't seem to find an answer fitting my problem, so I hope somebody can help me.

I want to display several image streams in a Unity scene. I have several GameObjects, each with the same loading-script attached and load my images via a coroutine in this script:

IEnumerator Load() { Texture2D tex = new Texture2D(4, 4, TextureFormat.DXT1, false); while (true) { WWW www = new WWW(url); yield return www; www.LoadImageIntoTexture(tex); img.texture = tex; } }

(Where img.texture is my image in the scene and url is the url i'm loading from).

This works fine for loading the images, but I notice the images load/ stream faster once I start more coroutines. To clarify, if i have 1 image stream it's updating the images at a certain speed but if i have, e.g. 3 image streams (each having a coroutine for loading) suddenly all 3 streams load images faster than with 1 stream.

I tried adding a yield return new WaitForFixedUpdate(); at the end of the coroutine but it didn't help, and i have no idea how to achieve a regular pace in loading new images, independent how many streams/coroutines i have at the same time? I hope it's clear what i mean and any help is appreciated!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · Jul 17, 2017 at 09:03 PM

I can't say for sure, but it's probably a question of whether you are loading sequentially or concurrently.

If you have three coroutines, do they all start at the same time? If so, they send their requests more or less at the same time, and get their responses back very quickly one after the other.

If you have one coroutine, then each has to wait for the previous to complete before it can start the next.

Even though the first method is faster when you have one user, though, it could cause problems if the web server is unable to keep up with the volume of many users. Using the second method in that situation would give it a chance to breathe and may increase stability.

Comment
Add comment · Show 4 · 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 KW90 · Jul 17, 2017 at 09:09 PM 0
Share

There are 3 different coroutines but they don't start at the same time. The user can choose to display 1, 2, 3, .. image streams at the same time. Once he starts a stream a new gameobject with the image-loading-script is instantiated and the coroutine started.

So I noticed if i display 1 stream it's updating images at a certain speed but if i choose more streams the speed increases.. is this "normal" behaviour or can i regulate it somehow?

avatar image FortisVenaliter KW90 · Jul 17, 2017 at 09:13 PM 0
Share

It could also be simple caching on the server side. $$anonymous$$ost servers are smart enough to know that if one file is requested, other files nearby will likely be requested too and cache those for easy transmission.

So, it could by that by requesting one, you're inadvertently telling the server "queue those others up, I may need them soon", so it's much faster after the first.

avatar image KW90 FortisVenaliter · Jul 17, 2017 at 09:17 PM 0
Share

I see, so it doesn't have to do with the corooutines or with the way I am loading the images? Interesting, I didn't think of that.. So the way i'm handling this seems fine to you? Displaying image streams by starting 1 coroutine for each stream and looping in it? Thanks a lot!

Show more comments

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

71 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

Related Questions

Coroutines and waiting for a function to finish execution 1 Answer

Yield everytime boolean is True (C#) 1 Answer

How do I use Yield in C#? 3 Answers

Animation Event issue what am I doing wrong here 2 Answers

Activating 3 rotations based on multiple presses on one key 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