function Update() {
method1();
method2();
}
function method1() {
var www : WWW = new WWW (url);
yield www;
method3()
}
function method2(){
}
function method3(){
}
Because of the yeild the order of the methods called is:
update(), method1(), method2(), method3()
I want to method1() to complete before calling method2().
So the order I want is this:
update(), method1(), method3(), method2().
You can’t do it that way, because you’re calling method1 in Update, which launches a new instance of method1 every frame, so you soon have hundreds of instances of method1 running. I would recommend not using Update for this; it causes major problems when trying to schedule coroutines. You can hack around it by setting booleans and so on, but it’s much easier and cleaner just to not use Update.
So what would be the preferred method if I want to call method1 and method2 periodically?
What happens if I use the following:
function Update() {
methodWrapper()
}
function methodWrapper() {
yield method1();
method2();
}
function method1() {
var www : WWW = new WWW (url);
yield www;
method3()
}
function method2(){
}
function method3(){
}
It seems to work. But I am curious what happens if the method calls do not finish before next update call?
You’re still doing the same thing, namely starting a new instance of methodWrapper every frame. It “works” but not really. Lose Update entirely, and only use coroutines.