A great big thank-you to ALDONETTO who actually did find the actual answer to this actual question, thank you very much Aldo.
The solution is simply that the print-to-the-console statement is buggy / behaves strangely.
Simply change the test routine to this form:
var someThing:Transform;
function runMeOneChunkAtATime()
{
for(x=0;x<100000000;++x) r += Mathf.Sqrt(x+r);
print("aaa");
someThing.position.x +=50; // add this line
yield; // just the one needed
etc...
}
And, thanks to Aldonetto, you will see that it performs perfectly and consistently in moving the object - while the print statement perfectly and consistently exhibits the strange behaviour explained below. (You will see the two things matching and then not matching in time.)
An interesting practical upshot of this:
If you are using the print statement to debug time-based programming, it does not work reliably. BUT if you add the bizarre “double-yield” as a quick fix during development – in fact the print statement will then effectively work properly for you during development.
Once again thank you very much Aldonetto for the awesome find. Thanks.
If you are truly an expert with yield and coroutines … perhaps you can explain this!
In Javascript/Unityscript. Make a testing button …
function OnGUI()
{
if (GUI.Button (Rect (400,10,70,50), "TEST"))
{ runMeOneChunkAtATime(); }
}
Now the following test routine …
function runMeOneChunkAtATime()
{
var r:float;
var x:int;
for(x=0;x<100000000;++x) r += Mathf.Sqrt(x+r);
print("aaa");
yield;
yield;
for(x=0;x<100000000;++x) r += Mathf.Sqrt(x+r);
print("bbb");
yield;
yield;
for(x=0;x<100000000;++x) r += Mathf.Sqrt(x+r);
print("ccc");
yield;
yield;
for(x=0;x<100000000;++x) r += Mathf.Sqrt(x+r);
print("ddd");
yield;
yield;
}
Now - why have double yield statements in each position?
First: put just ONE yield statement in each place, as you wold expect, and run it.
Notice it “doesn’t work” - the first one “does not pause”. Notice ‘aaa’ and ‘bbb’ appear on the console with no time gap between.
Now try it with double yield in each position. Notice the behaviour is perfectly what you would expect.
How to explain?