Skip to content

Instantly share code, notes, and snippets.

@hariedo
Last active May 14, 2025 13:35
Show Gist options
  • Save hariedo/e396ec4ca807bea97885079ac67227ca to your computer and use it in GitHub Desktop.
Save hariedo/e396ec4ca807bea97885079ac67227ca to your computer and use it in GitHub Desktop.
// The magical Start() method can also be treated as a coroutine if it returns
// IEnumerator. This lets a component class behave linearly, or at least start
// up with linear logic such as waiting for the right conditions to begin the
// Update() loop.
public class WaitToStartBehaviour: MonoBehaviour
{
// all the usual Singleton stuff (optional)
public VitalThing vital = null;
public List<ImportantThing> importantThings = new();
public bool IsEverythingReady() =>
vital != null && importantThings.Count > 0;
IEnumerator Start()
{
while (!IsEverythingReady())
yield return null;
DoStartupStuffThatNeedsEverythingReady();
}
DoStartupStuffThatNeedsEverythingReady()
{
//...
}
// all the other things this class does
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment