NetworkService

High-level orchestrator for the full multiplayer service lifecycle. Manages connecting to a backend platform, authenticating users, creating and joining sessions, kicking players, and tearing down connections. Owned by NetworkManager and accessed via NetworkManager.Service.

Definition

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

public class NetworkService

Remarks

NetworkService delegates all platform-specific operations to an IServiceAdapter instance, which is created based on the NetworkServiceType passed to Connect(). Currently, only the Unity Gaming Services adapter (UnityServiceAdapter) is fully implemented; Steam and Epic adapters are stubbed behind preprocessor directives.

The class also manages the NetworkTransport component, adding the correct transport (e.g. UnityTransport, FacepunchTransport) to the Netcode NetworkManager GameObject.

Connection approval is handled internally by delegating to NetworkSession.OnConnectionApproval(), which validates that no duplicate user IDs join the same session.

Quick Lookup

Goal
How

Connect to backend

await service.Connect(NetworkServiceType.UNITY)

Sign in anonymously

await service.SignIn(NetworkServiceType.UNITY)

Quick start (auto join/create)

await service.QuickStart()

Create a session

await service.CreateSession("MySession", 4)

Join a session by ID

await service.JoinSession(sessionId)

Query available sessions

var sessions = await service.QuerySessions()

Leave current session

await service.LeaveSession()

Kick a player

await service.KickPlayer(player)

Full shutdown

service.Shutdown()

Check connection state

service.IsConnected, service.IsSignedIn, service.InSession

Properties

User

The currently authenticated user. null if not signed in.

Session

The current network session. null if not in a session.

IsConnected

true if a service adapter has been created (i.e. Connect() was called).

IsSignedIn

true if the user has authenticated via SignIn().

InSession

true if the user is currently in a session.

Events

OnJoinedSession

Invoked when the local user successfully creates or joins a session. Passes the NetworkSession instance.

OnLeftSession

Invoked when the local user leaves a session. Passes the NetworkSession instance.

Methods

Connect

Creates a platform-specific service adapter and transport layer, then initializes the adapter.

Parameter
Type
Description

serviceType

NetworkServiceType

The backend platform to connect to

SignIn

Authenticates anonymously via the service adapter and stores the resulting NetworkUser. Sets the Netcode connection data payload.

Parameter
Type
Description

serviceType

NetworkServiceType

The backend platform to sign in to

QuickStart

Queries for existing sessions and joins the first one found. If no sessions exist, creates a new one.

Parameter
Type
Description

sessionName

string

Optional name for the session if one is created

QuerySessions

Queries the backend for available sessions.

Parameter
Type
Description

queryOptions

QuerySessionsOptions

Optional filter/sort options for the query

Returns: A list of NetworkSessionInfo describing available sessions.

CreateSession

Creates a new multiplayer session and invokes OnJoinedSession.

Parameter
Type
Description

sessionName

string

Optional display name for the session

maxConnections

int

Maximum number of players allowed (default: 4)

JoinSession

Joins an existing session by its ID and invokes OnJoinedSession.

Parameter
Type
Description

sessionID

string

The unique identifier of the session to join

LeaveSession

Leaves the current session and invokes OnLeftSession. No-op if not in a session.

KickPlayer

Removes a player from the session and disconnects their client.

Parameter
Type
Description

player

NetworkPlayer

The player to kick

circle-exclamation

SignOut

Deauthenticates from the backend service and clears the user reference.

Disconnect

Destroys the transport component and clears the service adapter. Synchronous operation.

Shutdown

Performs a full teardown in order: shuts down the session, signs out, then disconnects. No-op if not connected.

PrintSessionInfo

Runtime debug command that logs the current session's details (ID, name, max connections, host, players).

Common Pitfalls

circle-exclamation
circle-exclamation

Examples

Full Connection Flow

See Also

Last updated