Skip to content

Instantly share code, notes, and snippets.

@Novack
Forked from karljj1/AddPlayerLoopCallback.cs
Created August 16, 2020 01:21
Show Gist options
  • Save Novack/6c5482074e7da541959b701a5bea6b1d to your computer and use it in GitHub Desktop.
Save Novack/6c5482074e7da541959b701a5bea6b1d to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.LowLevel;
using UnityEngine.PlayerLoop;
public static class AddPlayerLoopCallback
{
// Add a callback to the PreUpdate phase
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void Setup()
{
var loop = PlayerLoop.GetCurrentPlayerLoop();
for (int i = 0; i < loop.subSystemList.Length; ++i)
{
if ( loop.subSystemList[i].type == typeof(PreUpdate))
{
loop.subSystemList[i].updateDelegate += Update;
}
}
PlayerLoop.SetPlayerLoop(loop);
}
static void Update()
{
Debug.Log("PreUpdate");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment