EnqueueOnMainThread
Queues a parameterless operation on Unity’s main thread through the shared runtime manager.
Static hand-offC# API
static void EnqueueOnMainThread(Action function);
Description
Use the static manager API when a script needs ThreadHarmonizer’s hand-off workflow without inheriting from MonoBehaviourMultithreaded. The operation is queued asynchronously, so the calling worker continues without waiting for the Unity-side apply step.
No custom base class requiredThe static API is available to ordinary MonoBehaviour scripts and other compatible code.
Keep applies smallPerform expensive work before the hand-off and queue only the required Unity-side change.
Parameters
NameTypeDescription
functionActionA parameterless function with no return value that will execute on Unity’s main thread.Apply a worker result from a regular MonoBehaviour
using ThreadHarmonizerEngine;
using UnityEngine;
public class StaticPositionCalculator : MonoBehaviour
{
private void Start()
{
Vector3 startPosition = transform.position;
ThreadHarmonizerManager.EnqueueOnWorker(() =>
{
Vector3 nextPosition = startPosition + Vector3.right * 2f;
ThreadHarmonizerManager.EnqueueOnMainThread(() =>
{
transform.position = nextPosition;
});
});
}
}
