UnityThreadUtils

Internal static utility that captures Unity's main thread context by invoking the non-public Unity.Services.Core.UnityThreadUtils.CaptureUnityThreadInfo() method via reflection. Required before calling UnityServices.InitializeAsync() to ensure async continuations execute on the correct thread.

Definition

Namespace: Paragon.Core.Network Assembly: Paragon.dll

internal static class UnityThreadUtils

Remarks

Unity Gaming Services' internal async machinery relies on captured SynchronizationContext information to marshal continuations back to the Unity main thread. The method CaptureUnityThreadInfo() on the internal Unity.Services.Core.UnityThreadUtils class performs this capture, but it is not publicly accessible.

This utility uses reflection to locate and invoke that method:

  1. Static constructor — Resolves the Unity.Services.Core.UnityThreadUtils type via Type.GetType() and caches the CaptureUnityThreadInfo MethodInfo using BindingFlags.Static | BindingFlags.NonPublic.

  2. CaptureUnityThreadInfo() — Invokes the cached method. Must be called on the Unity main thread, before UnityServices.InitializeAsync().

This is called by UnityServiceAdapter.Initialize() as the very first step of SDK initialization.

Quick Lookup

Goal
How

Capture Unity thread context

UnityThreadUtils.CaptureUnityThreadInfo()

When to call

Before UnityServices.InitializeAsync(), on the main thread

Fields

captureUnityThreadInfoMethod

Cached MethodInfo for the non-public static method Unity.Services.Core.UnityThreadUtils.CaptureUnityThreadInfo.

Resolved in the static constructor via:

Methods

CaptureUnityThreadInfo

Invokes the cached reflection method to capture Unity's main thread synchronization context.

Behavior: Calls captureUnityThreadInfoMethod.Invoke(null, null) — a parameterless static method invocation.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated