SlowUpdate

Unity’s coroutines don’t have a concept of a slow update loop, but MEC coroutines do.

The slow update loop runs (by default) at 7 times a second. It uses absolute timescale, so when you slow down Unity’s timescale it will not slow down SlowUpdate. SlowUpdate works great for tasks like displaying text to the user, since if you were to update the value any faster than that then the user wouldn’t really be able to see those rapid changes anyway.

There are two major differences between using SlowUpdate and just always yielding with “yield return Timing.WaitForSeconds(1f/7f);”. The first is the absolute timescale, and the second is that all SlowUpdate ticks happen at the same time. This is important, since changing a text box 7 times a second only looks good if all text boxes change during the same frame.

Timing.RunCoroutine(_UpdateTime(), Segment.SlowUpdate);

private IEnumerator<float> _UpdateTime()
{
    while(true)
    {
        clock = Timing.LocalTime;

        yield return 0f;
    }
}

 
SlowUpdate also works well for checking temporary debugging variables. For instance, if it takes a long time to rebuild your project you might set up a public bool in your script that will reset the values on that script. You’ll need to check if the value of that bool has been set to true periodically, and the perfect period to do that check is on SlowUpdate. When the user checks the checkbox it will feel like it responds immediately, but it will use far less processing in your app to check it every 1/7th of a second than 30 – 100 times per second (depending on your framerate).

NOTE: Unity’s Time.deltaTime variable will not return the correct value while in SlowUpdate, because Unity’s Time class knows nothing about this segment. Fortunately you can use Timing.DeltaTime instead when in SlowUpdate.

You can change the rate that SlowUpdate runs.

Timing.Instance.TimeBetweenSlowUpdateCalls = 3f;

 
The line above will make SlowUpdate only run once every 3 seconds.