Common Functions

Here are some Common fuctions that NetworkManager provides that you may find usful.

IsRunningLogic()

This checks if your current device is the host — the one responsible for running all the authoritative game logic.

  • In both normal and relay modes, it returns true only for the actual gameplay host (not the relay server).

  • This is what you should use when deciding who runs logic like health updates, object spawning, etc.

Think of this as: "Am I in charge of running the game world?"

NetworkManager.Instance().IsRunningLogic()
IsServerConnection()

This checks if your current connection is the server (the one routing messages).

  • In a relay setup, this will return true for the relay server — even though it's not running game logic.

  • In Embedded and Authoritative server, this also returns true for the headless instance.

Think of this as: "Am I the connection point for others?"

NetworkManager.Instance().IsServerConnection();
GetConnectionID()

Each Clients that join the session has a unique Connection ID used to distinguish between clients you can get that using.

NetworkManager.Instance().GetConnection().GetSocket().GetConnectionID();

You can do the same if you have the IClient of the client

//where client is an IClient 
(client as NetworkClient).GetConnectionId();
DisableAutoLoadSceneElements()

ObjectNet AutoMatically detects elements that are existing on the scene and send them to the newlly joinned client. However you can disable this process and do it manually using

//Disable the AutoLoad Scene elements system
NetworkManager.Instance().DisableAutoLoadSceneElements();
//Enable the AutoLoad scene elements system
NetworkManager.Instance().EnableAutoLoadSceneElements();
//request the scene elements from the server
NetworkManager.Instance().RequestRemoteSceneElements();  
GetLocalPlayerObject()

You can get the Local Player gameObject using

NetworkManager.Instance().GetLocalPlayerObject();
Get any Network Object

you can get the refrence of any Network Object in the scene using its NetworkID

//Get the GameObject of any Network object using the Network id 
GameObject instance = 
NetworkManager.Container.GetElement(NetworkId).GetGameObject();
GetActiveTransport()

You can get the currently used NetworkTransport name using

NetworkManager.Instance().GetActiveTransport().GetName();
Kick players

you can kick any player if you have their IClient just like the example below

client.GetTransport().Disconnect()

Here is an example that will kick all players except for the host

IClient[] clients = NetworkManager.Instance().GetConnectedClients<IClient>();
foreach (IClient client in clients) {                
    client.GetTransport().Disconnect();
 }

For a complete list, refer to the API Documentation.

Last updated