Skip to content

Instantly share code, notes, and snippets.

@capnslipp
Created May 18, 2014 01:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capnslipp/acfec93b5763901d6893 to your computer and use it in GitHub Desktop.
Save capnslipp/acfec93b5763901d6893 to your computer and use it in GitHub Desktop.
Unity LateFixedUpdate pattern test script
using UnityEngine;
using System.Collections;
public class TestLateFixedUpdate : MonoBehaviour
{
void OnEnable() {
StartCoroutine("RunLateFixedUpdate");
}
void OnDisable() {
StopCoroutine("RunLateFixedUpdate");
}
IEnumerator RunLateFixedUpdate() {
while (true) {
yield return new WaitForFixedUpdate();
LateFixedUpdate();
}
}
int _updateCount = 0;
void Update()
{
Debug.Log(this.GetType()+": Update #"+(++_updateCount)+" at "+Time.time);
}
int _fixedUpdateCount = 0;
void FixedUpdate()
{
Debug.Log(this.GetType()+": FixedUpdate #"+(++_fixedUpdateCount)+" at "+Time.time);
}
int _lateFixedUpdateCount = 0;
void LateFixedUpdate()
{
Debug.Log(this.GetType()+": LateFixedUpdate #"+(++_lateFixedUpdateCount)+" at "+Time.time);
}
}
@capnslipp
Copy link
Author

Test run output:

TestLateFixedUpdate: FixedUpdate #1 at 0
TestLateFixedUpdate: LateFixedUpdate #1 at 0
TestLateFixedUpdate: Update #1 at 0
TestLateFixedUpdate: FixedUpdate #2 at 0.02
TestLateFixedUpdate: LateFixedUpdate #2 at 0.02
TestLateFixedUpdate: Update #2 at 0.02
TestLateFixedUpdate: FixedUpdate #3 at 0.04
TestLateFixedUpdate: LateFixedUpdate #3 at 0.04
TestLateFixedUpdate: Update #3 at 0.04
TestLateFixedUpdate: FixedUpdate #4 at 0.06
TestLateFixedUpdate: LateFixedUpdate #4 at 0.06
TestLateFixedUpdate: Update #4 at 0.06
TestLateFixedUpdate: Update #5 at 0.06395799
TestLateFixedUpdate: Update #6 at 0.06789303
TestLateFixedUpdate: Update #7 at 0.07189202
TestLateFixedUpdate: Update #8 at 0.07597399
TestLateFixedUpdate: Update #9 at 0.07991099
TestLateFixedUpdate: FixedUpdate #5 at 0.08
TestLateFixedUpdate: LateFixedUpdate #5 at 0.08
TestLateFixedUpdate: Update #10 at 0.08387703
…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment