Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example of how to do delayed initialization - spreading heavy initialization workloads across multiple frames.
private static int newID = 0;
private int id;
private bool initialized = false;
IEnumerator Start ()
{
id = newID++;
for (int i = 0; i < id; i++)
{
yield return null;
}
// Do initialization
initialized = true;
}
void Update ()
{
if (!initialized)
{
return;
}
// Do work
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment