yield WaitForSeconds waits for too long.

When I run an empty project with this script attached to the main camera, the lag counter increments. The fixed one does not. I have a quadcore, so I'd say the processing power should be sufficient.

var currTime : float;
var lag : int;

var currFixedTime : float;
var fixedLag : int;
function Start()
{
    Time.fixedDeltaTime=0.05;
    while(true)
    {
        if (Time.time-currTime>0.1)
            lag +=1;
        currTime = Time.time;
        yield WaitForSeconds(0.05);
    }
}

function FixedUpdate()
{
    if (Time.time - currFixedTime > 0.1)
        fixedLag +=1;
    currFixedTime = Time.time;
}

function OnGUI()
{
    GUILayout.Label("Time: " + currTime);
    GUILayout.Label("Lag: " + lag);
    GUILayout.Label("Fixed: " + fixedLag);
}

I assume I get the lags because WaitForSeconds is somehow tied into the framerate. How can I get the behaviour I'm getting from FixedUpdate, without using FixedUpdate? (Still want my physics to be calculated 50 times per second)

-Bonus Question:

Are NetworkViews synchronization lagging in the same way as the WaitForSeconds?

Try removing the if statement in the while loop and just run the yield.

It could well be that you're using a large amount of memory, and every 20 seconds or so it's hitting a Garbage Collection.

Alternatively, it could be caused by an already low frame rate if you're trying to render too much.

Hard to tell without more information though, but it's probably a mixture of both.