Skip to content

Instantly share code, notes, and snippets.

@AngryAnt
Created June 6, 2011 13:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AngryAnt/1010234 to your computer and use it in GitHub Desktop.
Save AngryAnt/1010234 to your computer and use it in GitHub Desktop.
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