Skip to content

ActionQueue: The Main Thread Dispatcher

While Signals use this internally, the ActionQueue is exposed for general use. It solves the common problem: “I am in a background thread/task, but I need to touch a Unity GameObject.”

  • Thread-Safe Enqueue: Call from anywhere.
  • Phase Control: Choose exactly when the code runs (Update, LateUpdate, FixedUpdate).
  • Load Balancing: Limits execution time per frame to prevent FPS spikes.
// Run this block on the main thread as soon as possible
ActionQueue.Enqueue(() =>
{
transform.position = Vector3.zero; // Safe Unity API usage
});
// Avoid Closure Allocations by passing parameters
ActionQueue.Enqueue<int>(UpdateUI, newScore);
// Target specific loops
ActionQueue.EnqueueFixedUpdate(PhysicsCalculation);