Skip to main content

Unity.Netcode.NetworkManager

The main component of the library

Inheritance#

System.Dynamic.ExpandoObject

System.Dynamic.ExpandoObject

Implements#

INetworkUpdateSystem

Namespace: System.Dynamic.ExpandoObject#
Assembly: MLAPI.dll#
Syntax#
public class NetworkManager : MonoBehaviour, INetworkUpdateSystem

DontDestroy#

Gets or sets if the NetworkManager should be marked as DontDestroyOnLoad

Declaration#

public bool DontDestroy

Field Value#

TypeDescription
System.Boolean

LogLevel#

The log level to use

Declaration#

public LogLevel LogLevel

Field Value#

TypeDescription
LogLevel

NetworkConfig#

The current NetworkConfig

Declaration#

public NetworkConfig NetworkConfig

Field Value#

TypeDescription
NetworkConfig

PendingClients#

Gets a dictionary of the clients that have been accepted by the transport but are still pending by the Netcode. This is only populated on the server.

Declaration#

public readonly Dictionary<ulong, PendingClient> PendingClients

Field Value#

TypeDescription
System.Collections.Generic.Dictionary\<System.UInt64, PendingClient>

RunInBackground#

Gets or sets if the application should be set to run in background

Declaration#

public bool RunInBackground

Field Value#

TypeDescription
System.Boolean

#

ConnectedClients#

Gets a dictionary of connected clients and their clientId keys. This is only accessible on the server.

Declaration#

public IReadOnlyDictionary<ulong, NetworkClient> ConnectedClients { get; }

Property Value#

TypeDescription
IReadOnlyDictionary\<System.UInt64, NetworkClient<

ConnectedClientsIds#

Gets a list of just the IDs of all connected clients. This is only accessible on the server.

Declaration#

public IReadOnlyList<ulong> ConnectedClientsIds { get; }

Property Value#

TypeDescription
IReadOnlyList\<System.UInt64<

ConnectedClientsList#

Gets a list of connected clients. This is only accessible on the server.

Declaration#

public IReadOnlyList<NetworkClient> ConnectedClientsList { get; }

Property Value#

TypeDescription
IReadOnlyList\< NetworkClient<

ConnectedHostname#

The current host name we are connected to, used to validate certificate

Declaration#

public string ConnectedHostname { get; }

Property Value#

TypeDescription
System.String

CustomMessagingManager#

Declaration#

public CustomMessagingManager CustomMessagingManager { get; }

Property Value#

TypeDescription
CustomMessagingManager

IsClient#

Gets Whether or not a client is running

Declaration#

public bool IsClient { get; }

Property Value#

TypeDescription
System.Boolean

IsConnectedClient#

Gets if we are connected as a client

Declaration#

public bool IsConnectedClient { get; }

Property Value#

TypeDescription
System.Boolean

IsHost#

Gets if we are running as host

Declaration#

public bool IsHost { get; }

Property Value#

TypeDescription
System.Boolean

IsListening#

Gets Whether or not we are listening for connections

Declaration#

public bool IsListening { get; }

Property Value#

TypeDescription
System.Boolean

IsServer#

Gets Whether or not a server is running

Declaration#

public bool IsServer { get; }

Property Value#

TypeDescription
System.Boolean

LocalClient#

Gets the local NetworkClient for this client.

Declaration#

public NetworkClient LocalClient { get; }

Property Value#

TypeDescription
NetworkClient

LocalClientId#

Returns ServerClientId if IsServer or LocalClientId if not

Declaration#

public ulong LocalClientId { get; }

Property Value#

TypeDescription
System.UInt64

LocalTime#

Declaration#

public NetworkTime LocalTime { get; }

Property Value#

TypeDescription
NetworkTime

NetworkTickSystem#

Declaration#

public NetworkTickSystem NetworkTickSystem { get; }

Property Value#

TypeDescription
NetworkTickSystem

NetworkTimeSystem#

Declaration#

public NetworkTimeSystem NetworkTimeSystem { get; }

Property Value#

TypeDescription
NetworkTimeSystem

PrefabHandler#

Declaration#

public NetworkPrefabHandler PrefabHandler { get; }

Property Value#

TypeDescription
NetworkPrefabHandler

SceneManager#

Declaration#

public NetworkSceneManager SceneManager { get; }

Property Value#

TypeDescription
NetworkSceneManager

ServerClientId#

Gets the networkId of the server

Declaration#

public ulong ServerClientId { get; }

Property Value#

TypeDescription
System.UInt64

ServerTime#

Declaration#

public NetworkTime ServerTime { get; }

Property Value#

TypeDescription
NetworkTime

Singleton#

The singleton instance of the NetworkManager

Declaration#

public static NetworkManager Singleton { get; }

Property Value#

TypeDescription
NetworkManager

SpawnManager#

Gets the SpawnManager for this NetworkManager

Declaration#

public NetworkSpawnManager SpawnManager { get; }

Property Value#

TypeDescription
NetworkSpawnManager

#

DisconnectClient(UInt64)#

Disconnects the remote client.

Declaration#

public void DisconnectClient(ulong clientId)

Parameters#

TypeNameDescription
System.UInt64clientIdThe ClientId to disconnect

GetNetworkPrefabOverride(GameObject)#

Returns the to use as the override as could be defined within the NetworkPrefab list Note: This should be used to create pools (with NetworkObject components) under the scenario where you are using the Host model as it spawns everything locally. As such, the override will not be applied when spawning locally on a Host. Related Classes and Interfaces: NetworkPrefabHandler INetworkPrefabInstanceHandler

Declaration#

public GameObject GetNetworkPrefabOverride(GameObject gameObject)

Parameters#

TypeNameDescription
GameObjectgameObjectthe to be checked for a NetworkManager defined NetworkPrefab override

Returns#

TypeDescription
GameObjecta that is either the override or if no overrides exist it returns the same as the one passed in as a parameter

NetworkUpdate(NetworkUpdateStage)#

Declaration#

public void NetworkUpdate(NetworkUpdateStage updateStage)

Parameters#

TypeNameDescription
NetworkUpdateStageupdateStage

SetSingleton()#

Declaration#

public void SetSingleton()

Shutdown()#

Globally shuts down the library. Disconnects clients if connected and stops server if running.

Declaration#

public void Shutdown()

StartClient()#

Starts a client

Declaration#

public bool StartClient()

Returns#

TypeDescription
System.Boolean

StartHost()#

Starts a Host

Declaration#

public bool StartHost()

Returns#

TypeDescription
System.Boolean

StartServer()#

Starts a server

Declaration#

public bool StartServer()

Returns#

TypeDescription
System.Boolean

#

ConnectionApprovalCallback#

The callback to invoke during connection approval

Declaration#

public event Action<byte[], ulong, NetworkManager.ConnectionApprovedDelegate> ConnectionApprovalCallback

Event Type#

TypeDescription
System.Action\<System.Byte[], System.UInt64, NetworkManager.ConnectionApprovedDelegate>

OnClientConnectedCallback#

The callback to invoke once a client connects. This callback is only ran on the server and on the local client that connects.

Declaration#

public event Action<ulong> OnClientConnectedCallback

Event Type#

TypeDescription
System.Action\<System.UInt64>

OnClientDisconnectCallback#

The callback to invoke when a client disconnects. This callback is only ran on the server and on the local client that disconnects.

Declaration#

public event Action<ulong> OnClientDisconnectCallback

Event Type#

TypeDescription
System.Action\<System.UInt64>

OnServerStarted#

The callback to invoke once the server is ready

Declaration#

public event Action OnServerStarted

Event Type#

TypeDescription
System.Action

Implements#

INetworkUpdateSystem

Extension Methods#

NetworkUpdateLoop.RegisterAllNetworkUpdates(INetworkUpdateSystem)

NetworkUpdateLoop.RegisterNetworkUpdate(INetworkUpdateSystem, NetworkUpdateStage)

NetworkUpdateLoop.UnregisterAllNetworkUpdates(INetworkUpdateSystem)

NetworkUpdateLoop.UnregisterNetworkUpdate(INetworkUpdateSystem, NetworkUpdateStage)