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 BerggreenDK · Jul 18, 2011 at 11:57 AM · wwwyieldpattern

Two yield or not two yield (pattern?)

Sorry for the lame subject, but I am having troubles with yield while loading some bytes from a WWW object in C#.

Task

Load multiple files with WWW from a webserver, from a UnityPlayer webclient.

But I need to wait for EVERY file, until the game can start.

Some of the files are leveldata telling how to build the level others are players and NPC data etc.

And everything is needed before the simulation/game may start.

Question

Should I spawn multiple WWW objects and yield them all or only one at the time? The server I am loading from could be different addresses (CDN's) so speed is not the problem. My problem is only what pattern is recommended and why and ... ouch! HOW?!

I have a yield running now, loading 1000 bytes from a webserver, it returns the 1000 bytes (sooner or later) but everything starts, so I will need to make some kinda state-machine globally too I guess.

I think I will yield until someone can answer this.

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 Peter G · Jul 18, 2011 at 04:55 PM 0
Share

It doesn't really matter because its all done on the main thread. So they will be done one at a time no matter how you slice it.

avatar image BerggreenDK · Jul 19, 2011 at 08:40 AM 0
Share

okay, but I still need to wait for them and then be able to use the data from them afterwards. They load text, bytes etc.

1 Reply

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

Answer by Peter G · Jul 19, 2011 at 01:13 AM

You can spawn them all at one time, but you probably won't save much time since Unity isn't multithreaded. Only one will ever be loading at any given time so your speed probably won't be noticeably different. It shouldn't change if one loads fully then you load the next one or if you load a little bit of each during each frame. Personally I would put it in a loop and load each one after the next just because it looks nice:

 for(var i = 0; i < URLS.Length; i++) {
       URLS[i] = new WWW(addresses[i]);
       yield return URLS[i];
       //do something else with the data;
 }

If you know .Net sockets you might be able to do something similar and then push that onto different threads.

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 BerggreenDK · Jul 19, 2011 at 08:39 AM 0
Share

that makes sense, but where do you store the data then or how do you index the found data?

avatar image BerggreenDK · Jul 19, 2011 at 08:41 AM 0
Share

Do I access the array of URLS (as a global array) after the FOR loop?

avatar image Peter G · Jul 19, 2011 at 01:40 PM 1
Share

Yes. The info will still be there URLS[i].text or whatever you need.

avatar image Peter G · Jul 19, 2011 at 01:42 PM 0
Share

You also might want to be concerned that you are allocating a lot of memory in a very short amount of time by doing it this way. Why can't you stream them in as you need them?

avatar image BerggreenDK · Jul 19, 2011 at 02:28 PM 0
Share

Its not a big memory issue as the objects and lists arent very long, I just need them all before I can create the level. Its a one way only level and a lagspike would ruin the competition part of it.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Trying to create a static class for WWW-based functions and such 0 Answers

Custom yield return 1 Answer

How to set timer for WWW helper? 1 Answer

How can I have a while(www is loading) loop? 1 Answer

yield return request never returns 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