Class SinglePlayerTransport
A transport that can be used to run a Netcode for GameObjects session in "single player" mode by assigning this transport to the NetworkTransport property before starting as a host.
Inherited Members
Namespace: Unity.Netcode.Transports.SinglePlayer
Assembly: Unity.Netcode.Runtime.dll
Syntax
public class SinglePlayerTransport : NetworkTransport
  Remarks
You can only start as a host when using this transport.
Properties
ServerClientId
A constant clientId that represents the server
When this value is found in methods such as Send, it should be treated as a placeholder that means "the server"
Declaration
public override ulong ServerClientId { get; }
  Property Value
| Type | Description | 
|---|---|
| ulong | 
Overrides
Methods
DisconnectLocalClient()
Disconnects the local client from the server
Declaration
public override void DisconnectLocalClient()
  Overrides
DisconnectRemoteClient(ulong)
Disconnects a client from the server
Declaration
public override void DisconnectRemoteClient(ulong clientId)
  Parameters
| Type | Name | Description | 
|---|---|---|
| ulong | clientId | The clientId to disconnect  | 
      
Overrides
GetCurrentRtt(ulong)
Gets the round trip time for a specific client. This method is optional
Declaration
public override ulong GetCurrentRtt(ulong clientId)
  Parameters
| Type | Name | Description | 
|---|---|---|
| ulong | clientId | The clientId to get the RTT from  | 
      
Returns
| Type | Description | 
|---|---|
| ulong | Returns the round trip time in milliseconds  | 
      
Overrides
Remarks
Will always return 0 since this transport is for a local single player session.
Initialize(NetworkManager)
Initializes the transport
Declaration
public override void Initialize(NetworkManager networkManager = null)
  Parameters
| Type | Name | Description | 
|---|---|---|
| NetworkManager | networkManager | optionally pass in NetworkManager  | 
      
Overrides
PollEvent(out ulong, out ArraySegment<byte>, out float)
Polls for incoming events, with an extra output parameter to report the precise time the event was received.
Declaration
public override NetworkEvent PollEvent(out ulong clientId, out ArraySegment<byte> payload, out float receiveTime)
  Parameters
| Type | Name | Description | 
|---|---|---|
| ulong | clientId | The clientId this event is for  | 
      
| ArraySegment<byte> | payload | The incoming data payload  | 
      
| float | receiveTime | The time the event was received, as reported by Time.realtimeSinceStartup.  | 
      
Returns
| Type | Description | 
|---|---|
| NetworkEvent | Returns the event type  | 
      
Overrides
Send(ulong, ArraySegment<byte>, NetworkDelivery)
Send a payload to the specified clientId, data and networkDelivery.
Declaration
public override void Send(ulong clientId, ArraySegment<byte> payload, NetworkDelivery networkDelivery)
  Parameters
| Type | Name | Description | 
|---|---|---|
| ulong | clientId | The clientId to send to  | 
      
| ArraySegment<byte> | payload | The data to send  | 
      
| NetworkDelivery | networkDelivery | The delivery type (QoS) to send data with  | 
      
Overrides
Shutdown()
Shuts down the transport
Declaration
public override void Shutdown()
  Overrides
StartClient()
Connects client to the server
Declaration
public override bool StartClient()
  Returns
| Type | Description | 
|---|---|
| bool | Returns success or failure  | 
      
Overrides
Remarks
This will always return false for SinglePlayerTransport. Always use StartServer().
StartServer()
Starts to listening for incoming clients
Declaration
public override bool StartServer()
  Returns
| Type | Description | 
|---|---|
| bool | Returns success or failure  | 
      
Overrides
Remarks
Always use StartHost() when hosting a local single player session.