Skip to content

Instantly share code, notes, and snippets.

@paulmasri
Last active March 22, 2021 15:42
Show Gist options
  • Select an option

  • Save paulmasri/412e5ed2aacfe616908433ea31874534 to your computer and use it in GitHub Desktop.

Select an option

Save paulmasri/412e5ed2aacfe616908433ea31874534 to your computer and use it in GitHub Desktop.
Equivalent of LateUpdate() but for FixedUpdate() in Unity
// Based on code by James Frowen https://james-frowen.github.io/unity_tips/latefixedupdate/
// but with order of execution switched so that LateFixedUpdate() is not called during OnEnable()
public void OnEnable()
{
StartCoroutine(RunLateFixedUpdate());
}
public void OnDisable()
{
StopCoroutine(RunLateFixedUpdate());
}
private IEnumerator RunLateFixedUpdate()
{
while (true)
{
yield return new WaitForFixedUpdate();
LateFixedUpdate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment