Unity

Concrete IServiceAdapter implementation using Unity Gaming Services (UGS). Provides authentication via UGS Authentication, session management via UGS Multiplayer, and relay-based networking for NAT traversal.

Architecture

spinner

Unity Gaming Services Dependencies

UGS Package
Class Used
Purpose

com.unity.services.core

UnityServices

SDK initialization

com.unity.services.authentication

AuthenticationService

Anonymous sign-in/sign-out

com.unity.services.multiplayer

MultiplayerService, ISession

Session creation, joining, querying

Session Lifecycle

spinner

Key Patterns

Relay Networking

UnityServiceAdapter.CreateSession() calls sessionOptions.WithRelayNetwork() to enable Unity Relay, which handles NAT traversal automatically. All sessions use relay-based transport by default.

Thread Context Capture

Unity Gaming Services requires main-thread context for proper async continuation. UnityThreadUtils uses reflection to call the internal Unity.Services.Core.UnityThreadUtils.CaptureUnityThreadInfo() method before SDK initialization.

Factory Method Pattern

UnityNetworkSession uses a static Create() factory method instead of a public constructor. This allows the creation to be async — the method waits for player synchronization (Yield.WaitUntil(() => session.synchronized)) before returning the fully-initialized session.

Classes

Class
Description

IServiceAdapter implementation using Unity Gaming Services

NetworkSession implementation wrapping Unity's ISession

Reflection utility for capturing Unity's main thread context

See Also

Last updated