Search Results for

    Show / Hide Table of Contents

    Class NetworkManager

    Inheritance
    Object
    NetworkManager
    NetworkRoomManager
    Namespace: Mirror
    Assembly: doc.dll
    Syntax
    public class NetworkManager : MonoBehaviour

    Fields

    | Improve this Doc View Source

    authenticator

    Declaration
    public NetworkAuthenticator authenticator
    Field Value
    Type Description
    NetworkAuthenticator
    | Improve this Doc View Source

    autoCreatePlayer

    Enable to automatically create player objects on connect and on scene change.

    Declaration
    public bool autoCreatePlayer
    Field Value
    Type Description
    Boolean
    | Improve this Doc View Source

    autoStartServerBuild

    Should the server auto-start when 'Server Build' is checked in build settings

    Declaration
    public bool autoStartServerBuild
    Field Value
    Type Description
    Boolean
    | Improve this Doc View Source

    clientLoadedScene

    True if the client loaded a new scene when connecting to the server.

    Declaration
    protected bool clientLoadedScene
    Field Value
    Type Description
    Boolean
    | Improve this Doc View Source

    dontDestroyOnLoad

    Enable to keep NetworkManager alive when changing scenes.

    Declaration
    public bool dontDestroyOnLoad
    Field Value
    Type Description
    Boolean
    | Improve this Doc View Source

    loadingSceneAsync

    Declaration
    public static AsyncOperation loadingSceneAsync
    Field Value
    Type Description
    AsyncOperation
    | Improve this Doc View Source

    maxConnections

    The maximum number of concurrent network connections to support.

    Declaration
    public int maxConnections
    Field Value
    Type Description
    Int32
    | Improve this Doc View Source

    networkAddress

    Server's address for clients to connect to.

    Declaration
    public string networkAddress
    Field Value
    Type Description
    String
    | Improve this Doc View Source

    offlineScene

    Automatically switch to this scene upon going offline (on start / on disconnect / on shutdown).

    Declaration
    public string offlineScene
    Field Value
    Type Description
    String
    | Improve this Doc View Source

    onlineScene

    Automatically switch to this scene upon going online (after connect/startserver).

    Declaration
    public string onlineScene
    Field Value
    Type Description
    String
    | Improve this Doc View Source

    playerPrefab

    The default prefab to be used to create player objects on the server.

    Declaration
    public GameObject playerPrefab
    Field Value
    Type Description
    GameObject
    | Improve this Doc View Source

    playerSpawnMethod

    Where to spawn players.

    Declaration
    public PlayerSpawnMethod playerSpawnMethod
    Field Value
    Type Description
    PlayerSpawnMethod
    | Improve this Doc View Source

    runInBackground

    Multiplayer games should always run in the background so the network doesn't time out.

    Declaration
    public bool runInBackground
    Field Value
    Type Description
    Boolean
    | Improve this Doc View Source

    serverTickRate

    Server Update frequency, per second. Use around 60Hz for fast paced games like Counter-Strike to minimize latency. Use around 30Hz for games like WoW to minimize computations. Use around 1-10Hz for slow paced games like EVE.

    Declaration
    public int serverTickRate
    Field Value
    Type Description
    Int32
    | Improve this Doc View Source

    spawnPrefabs

    Prefabs that can be spawned over the network need to be registered here.

    Declaration
    public List<GameObject> spawnPrefabs
    Field Value
    Type Description
    List<GameObject>
    | Improve this Doc View Source

    startPositionIndex

    Declaration
    public static int startPositionIndex
    Field Value
    Type Description
    Int32
    | Improve this Doc View Source

    startPositions

    List of transforms populated by NetworkStartPositions

    Declaration
    public static List<Transform> startPositions
    Field Value
    Type Description
    List<Transform>
    | Improve this Doc View Source

    transport

    Declaration
    protected Transport transport
    Field Value
    Type Description
    Transport

    Properties

    | Improve this Doc View Source

    isNetworkActive

    True if the server is running or client is connected/connecting.

    Declaration
    public bool isNetworkActive { get; }
    Property Value
    Type Description
    Boolean
    | Improve this Doc View Source

    mode

    Declaration
    public NetworkManagerMode mode { get; }
    Property Value
    Type Description
    NetworkManagerMode
    | Improve this Doc View Source

    networkSceneName

    The name of the current network scene.

    Declaration
    public static string networkSceneName { get; protected set; }
    Property Value
    Type Description
    String
    | Improve this Doc View Source

    numPlayers

    Number of active player objects across all connections on the server.

    Declaration
    public int numPlayers { get; }
    Property Value
    Type Description
    Int32
    | Improve this Doc View Source

    singleton

    The one and only NetworkManager

    Declaration
    public static NetworkManager singleton { get; }
    Property Value
    Type Description
    NetworkManager

    Methods

    | Improve this Doc View Source

    Awake()

    Declaration
    public virtual void Awake()
    | Improve this Doc View Source

    ConfigureHeadlessFrameRate()

    Set the frame rate for a headless builds. Override to disable or modify.

    Declaration
    public virtual void ConfigureHeadlessFrameRate()
    | Improve this Doc View Source

    FinishLoadScene()

    Declaration
    protected void FinishLoadScene()
    | Improve this Doc View Source

    GetStartPosition()

    Get the next NetworkStartPosition based on the selected PlayerSpawnMethod.

    Declaration
    public Transform GetStartPosition()
    Returns
    Type Description
    Transform
    | Improve this Doc View Source

    IsSceneActive(String)

    Declaration
    public static bool IsSceneActive(string scene)
    Parameters
    Type Name Description
    String scene
    Returns
    Type Description
    Boolean
    | Improve this Doc View Source

    LateUpdate()

    Declaration
    public virtual void LateUpdate()
    | Improve this Doc View Source

    OnApplicationQuit()

    Declaration
    public virtual void OnApplicationQuit()
    | Improve this Doc View Source

    OnClientChangeScene(String, SceneOperation, Boolean)

    Called from ClientChangeScene immediately before SceneManager.LoadSceneAsync is executed

    Declaration
    public virtual void OnClientChangeScene(string newSceneName, SceneOperation sceneOperation, bool customHandling)
    Parameters
    Type Name Description
    String newSceneName
    SceneOperation sceneOperation
    Boolean customHandling
    | Improve this Doc View Source

    OnClientConnect()

    Called on the client when connected to a server. By default it sets client as ready and adds a player.

    Declaration
    public virtual void OnClientConnect()
    | Improve this Doc View Source

    OnClientDisconnect()

    Called on clients when disconnected from a server.

    Declaration
    public virtual void OnClientDisconnect()
    | Improve this Doc View Source

    OnClientError(Exception)

    Declaration
    public virtual void OnClientError(Exception exception)
    Parameters
    Type Name Description
    Exception exception
    | Improve this Doc View Source

    OnClientError(TransportError, String)

    Called on client when transport raises an exception.

    Declaration
    public virtual void OnClientError(TransportError error, string reason)
    Parameters
    Type Name Description
    TransportError error
    String reason
    | Improve this Doc View Source

    OnClientNotReady()

    Called on clients when a servers tells the client it is no longer ready, e.g. when switching scenes.

    Declaration
    public virtual void OnClientNotReady()
    | Improve this Doc View Source

    OnClientSceneChanged()

    Called on clients when a scene has completed loaded, when the scene load was initiated by the server.

    Declaration
    public virtual void OnClientSceneChanged()
    | Improve this Doc View Source

    OnDestroy()

    Declaration
    public virtual void OnDestroy()
    | Improve this Doc View Source

    OnServerAddPlayer(NetworkConnectionToClient)

    Called on server when a client requests to add the player. Adds playerPrefab by default. Can be overwritten.

    Declaration
    public virtual void OnServerAddPlayer(NetworkConnectionToClient conn)
    Parameters
    Type Name Description
    NetworkConnectionToClient conn
    | Improve this Doc View Source

    OnServerChangeScene(String)

    Called from ServerChangeScene immediately before SceneManager.LoadSceneAsync is executed

    Declaration
    public virtual void OnServerChangeScene(string newSceneName)
    Parameters
    Type Name Description
    String newSceneName
    | Improve this Doc View Source

    OnServerConnect(NetworkConnectionToClient)

    Called on the server when a new client connects.

    Declaration
    public virtual void OnServerConnect(NetworkConnectionToClient conn)
    Parameters
    Type Name Description
    NetworkConnectionToClient conn
    | Improve this Doc View Source

    OnServerDisconnect(NetworkConnectionToClient)

    Called on the server when a client disconnects.

    Declaration
    public virtual void OnServerDisconnect(NetworkConnectionToClient conn)
    Parameters
    Type Name Description
    NetworkConnectionToClient conn
    | Improve this Doc View Source

    OnServerError(NetworkConnectionToClient, Exception)

    Declaration
    public virtual void OnServerError(NetworkConnectionToClient conn, Exception exception)
    Parameters
    Type Name Description
    NetworkConnectionToClient conn
    Exception exception
    | Improve this Doc View Source

    OnServerError(NetworkConnectionToClient, TransportError, String)

    Called on server when transport raises an exception. NetworkConnection may be null.

    Declaration
    public virtual void OnServerError(NetworkConnectionToClient conn, TransportError error, string reason)
    Parameters
    Type Name Description
    NetworkConnectionToClient conn
    TransportError error
    String reason
    | Improve this Doc View Source

    OnServerReady(NetworkConnectionToClient)

    Called on the server when a client is ready (= loaded the scene)

    Declaration
    public virtual void OnServerReady(NetworkConnectionToClient conn)
    Parameters
    Type Name Description
    NetworkConnectionToClient conn
    | Improve this Doc View Source

    OnServerSceneChanged(String)

    Called on server after a scene load with ServerChangeScene() is completed.

    Declaration
    public virtual void OnServerSceneChanged(string sceneName)
    Parameters
    Type Name Description
    String sceneName
    | Improve this Doc View Source

    OnStartClient()

    This is invoked when the client is started.

    Declaration
    public virtual void OnStartClient()
    | Improve this Doc View Source

    OnStartHost()

    This is invoked when a host is started.

    Declaration
    public virtual void OnStartHost()
    | Improve this Doc View Source

    OnStartServer()

    This is invoked when a server is started - including when a host is started.

    Declaration
    public virtual void OnStartServer()
    | Improve this Doc View Source

    OnStopClient()

    This is called when a client is stopped.

    Declaration
    public virtual void OnStopClient()
    | Improve this Doc View Source

    OnStopHost()

    This is called when a host is stopped.

    Declaration
    public virtual void OnStopHost()
    | Improve this Doc View Source

    OnStopServer()

    This is called when a server is stopped - including when a host is stopped.

    Declaration
    public virtual void OnStopServer()
    | Improve this Doc View Source

    OnValidate()

    Declaration
    public virtual void OnValidate()
    | Improve this Doc View Source

    RegisterStartPosition(Transform)

    Registers the transform of a game object as a player spawn location.

    This is done automatically by NetworkStartPosition components, but can be done manually from user script code.

    Declaration
    public static void RegisterStartPosition(Transform start)
    Parameters
    Type Name Description
    Transform start

    Transform to register.

    | Improve this Doc View Source

    Reset()

    Declaration
    public virtual void Reset()
    | Improve this Doc View Source

    ResetStatics()

    Declaration
    public static void ResetStatics()
    | Improve this Doc View Source

    ServerChangeScene(String)

    Change the server scene and all client's scenes across the network.

    Declaration
    public virtual void ServerChangeScene(string newSceneName)
    Parameters
    Type Name Description
    String newSceneName
    | Improve this Doc View Source

    Start()

    Declaration
    public virtual void Start()
    | Improve this Doc View Source

    StartClient()

    Starts the client, connects it to the server with networkAddress.

    Declaration
    public void StartClient()
    | Improve this Doc View Source

    StartClient(Uri)

    Starts the client, connects it to the server via Uri

    Declaration
    public void StartClient(Uri uri)
    Parameters
    Type Name Description
    Uri uri
    | Improve this Doc View Source

    StartHost()

    Starts a network "host" - a server and client in the same application.

    Declaration
    public void StartHost()
    | Improve this Doc View Source

    StartServer()

    Starts the server, listening for incoming connections.

    Declaration
    public void StartServer()
    | Improve this Doc View Source

    StopClient()

    Stops and disconnects the client.

    Declaration
    public void StopClient()
    | Improve this Doc View Source

    StopHost()

    This stops both the client and the server that the manager is using.

    Declaration
    public void StopHost()
    | Improve this Doc View Source

    StopServer()

    Stops the server from listening and simulating the game.

    Declaration
    public void StopServer()
    | Improve this Doc View Source

    UnRegisterStartPosition(Transform)

    Unregister a Transform from start positions.

    Declaration
    public static void UnRegisterStartPosition(Transform start)
    Parameters
    Type Name Description
    Transform start
    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX