- Home /
yield return www - What is www referring to?
In the instruction:
yield return www;
which method is being called in the WWW class of the www variable?
Hey should have probably pointed out that they are also discussed in detail here
Answer by whydoidoit · Nov 08, 2012 at 02:30 PM
It's not calling a method - its waiting for the object to say that its done and then continuing.
something like:
while(!www.isDone)
yield return null;
can you explain how it is waiting for the object to say that its done if it's only referencing the variable name?
I would understand your logic if it was: yield return www.WaitTillDone();
and even then, the execution would be blocked till WaitTillDone returned, right?
Hey sorry, just saw this per your comment above about stackexchange.
That code is the same as waiting for the object with yield return www;
That's because internally the implemented YieldInstruction on WWW just waits for the completion signal before indicating that it can continue. If you want to be involved in the process, then the code I've posted does exactly the same thing, but you could choose to abort if the process had taken too long - not an option with the normal yield.
so you consider that the download is being done asynchronously on a different thread (which starts by calling the WWW constructor), right? As it was pointed out on stackexchange, the main Unity thread seems to be, at least, responsible for the change in the www.isDone field.
Yes that's pretty much it - all coroutine processing and actually anything to do with a Unity object publicly is done on the main thread (to avoid their thread access exceptions).
So there will be some internal value that is being changed on completion, that thread then queues up a main thread change of the isDone value - actually this article I wrote shows how you can achieve that with your own threads - I guess that they are doing something similar.
Answer by Landern · Nov 08, 2012 at 02:29 PM
you are waiting for something to download, wait for it to complete then return the www object.
Quote from the documentation:
Simple access to web pages.
This is a small utility module for retrieving the contents of URLs.
You start a download in the background by calling WWW(url) which returns a new WWW object.
I know what it is used for, my question is about what specific mechanism is being used to wait for the WWW process to return. Typically a C# yield statement implements a state machine which controls the different operations and return values based on its current state (# of calls already performed). I don't understand how is this process being used here.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Another yield and www question 2 Answers
yield www loading local file blocks UI 0 Answers
Flip over an object (smooth transition) 3 Answers