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.”
Features
Section titled “Features”- 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 possibleActionQueue.Enqueue(() =>{ transform.position = Vector3.zero; // Safe Unity API usage});
// Avoid Closure Allocations by passing parametersActionQueue.Enqueue<int>(UpdateUI, newScore);
// Target specific loopsActionQueue.EnqueueFixedUpdate(PhysicsCalculation);