Skip to main content

Class ServerObjectManager

The ServerObjectManager.

Inheritance
System.Object
Syntax
public class ServerObjectManager : MonoBehaviour

Fields

NetIdGenerator

Declaration
public INetIdGenerator NetIdGenerator

Properties

Server

Declaration
public NetworkServer Server { get; }

DefaultVisibility

Declaration
public INetworkVisibility DefaultVisibility { get; }

Methods

ReplaceCharacter(INetworkPlayer, NetworkIdentity, Int32, Boolean)

This replaces the player object for a connection with a different player object. The old player object is not destroyed. If a connection already has a player object, this can be used to replace that object with a different player object. This does NOT change the ready state of the connection, so it can safely be used while changing scenes.

Declaration
public void ReplaceCharacter(INetworkPlayer player, NetworkIdentity character, int prefabHash, bool keepAuthority = false)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerConnection which is adding the player.
Mirage.NetworkIdentitycharacterPlayer object spawned for the player.
System.Int32prefabHash
System.BooleankeepAuthorityDoes the previous player remain attached to this connection?

ReplaceCharacter(INetworkPlayer, NetworkIdentity, Boolean)

This replaces the player object for a connection with a different player object. The old player object is not destroyed. If a connection already has a player object, this can be used to replace that object with a different player object. This does NOT change the ready state of the connection, so it can safely be used while changing scenes.

Declaration
public void ReplaceCharacter(INetworkPlayer player, NetworkIdentity identity, bool keepAuthority = false)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerConnection which is adding the player.
Mirage.NetworkIdentityidentityPlayer object spawned for the player.
System.BooleankeepAuthorityDoes the previous player remain attached to this connection?

AddCharacter(INetworkPlayer, NetworkIdentity, Int32)

When is received from a player, the server calls this to associate the character GameObject with the NetworkPlayer. When a character is added for a player the object is automatically spawned, so you do not need to call ServerObjectManager.Spawn for that object. This function is used for adding a character, not replacing. If there is already a character then use instead.

Declaration
public void AddCharacter(INetworkPlayer player, NetworkIdentity character, int prefabHash)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerthe Player to add the character to
Mirage.NetworkIdentitycharacterThe Network Object to add to the Player. Can be spawned or unspawned. Calling this method will respawn it.
System.Int32prefabHashNew prefab hash to give to the player, used for dynamically creating objects at runtime.

AddCharacter(INetworkPlayer, NetworkIdentity)

When is received from a player, the server calls this to associate the character GameObject with the NetworkPlayer. When a character is added for a player the object is automatically spawned, so you do not need to call ServerObjectManager.Spawn for that object. This function is used for adding a character, not replacing. If there is already a character then use instead.

Declaration
public void AddCharacter(INetworkPlayer player, NetworkIdentity identity)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerthe Player to add the character to
Mirage.NetworkIdentityidentity

RemoveCharacter(INetworkPlayer, Boolean)

Removes the character from a player, with the option to keep the player as the owner of the object

Declaration
public void RemoveCharacter(INetworkPlayer player, bool keepAuthority = false)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayer
System.BooleankeepAuthority

DestroyCharacter(INetworkPlayer, Boolean)

Removes and destroys the character from a player

Declaration
public void DestroyCharacter(INetworkPlayer player, bool destroyServerObject = true)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayer
System.BooleandestroyServerObject

Spawn(NetworkIdentity, Int32, INetworkPlayer)

Assigns prefabHash to the identity and then spawns it with owner

can only be set on an identity if the current value is Empty

This method is useful if you are creating network objects at runtime and both server and client know what  to set on an object
Declaration
public void Spawn(NetworkIdentity identity, int prefabHash, INetworkPlayer owner = null)
Parameters
TypeNameDescription
Mirage.NetworkIdentityidentity
System.Int32prefabHashThe prefabHash of the object to spawn. Used for custom spawn handlers.
Mirage.INetworkPlayerownerThe connection that has authority over the object

Spawn(NetworkIdentity, INetworkPlayer)

Spawns the identity and keeping owner as

Declaration
public void Spawn(NetworkIdentity identity, INetworkPlayer owner)
Parameters
TypeNameDescription
Mirage.NetworkIdentityidentity
Mirage.INetworkPlayerowner

Spawn(NetworkIdentity)

Spawns the identity and assigns owner to be it's owner

Declaration
public void Spawn(NetworkIdentity identity)
Parameters
TypeNameDescription
Mirage.NetworkIdentityidentity

Destroy(GameObject, Boolean)

Destroys this object and corresponding objects on all clients. Game object to destroy. Sets if server object will also be destroyed

Declaration
public void Destroy(GameObject gameObject, bool destroyServerObject = true)
Parameters
TypeNameDescription
GameObjectgameObject
System.BooleandestroyServerObject

Destroy(NetworkIdentity, Boolean)

Destroys this object and corresponding objects on all clients. Game object to destroy. Sets if server object will also be destroyed

Declaration
public void Destroy(NetworkIdentity identity, bool destroyServerObject = true)
Parameters
TypeNameDescription
Mirage.NetworkIdentityidentity
System.BooleandestroyServerObject

SpawnSceneObjects()

This causes NetworkIdentity objects in a scene to be spawned on a server.

Calling SpawnObjects() causes all scene objects to be spawned.
It is like calling Spawn() for each of them.
Declaration
public void SpawnSceneObjects()

SpawnVisibleObjects(INetworkPlayer)

Sends spawn message for scene objects and other visible objects to the given player if it has a character

If there is a then this will be called after the client finishes loading the scene and sends

Declaration
public void SpawnVisibleObjects(INetworkPlayer player)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerThe player to spawn objects for

SpawnVisibleObjects(INetworkPlayer, Boolean)

Sends spawn message for scene objects and other visible objects to the given player if it has a character

Declaration
public void SpawnVisibleObjects(INetworkPlayer player, bool ignoreHasCharacter)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerThe player to spawn objects for
System.BooleanignoreHasCharacterIf true will spawn visibile objects even if player does not have a spawned character yet

SpawnVisibleObjects(INetworkPlayer, NetworkIdentity)

Sends spawn message for scene objects and other visible objects to the given player if it has a character

Declaration
public void SpawnVisibleObjects(INetworkPlayer player, NetworkIdentity skip)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerThe player to spawn objects for
Mirage.NetworkIdentityskip

SpawnVisibleObjects(INetworkPlayer, Boolean, NetworkIdentity)

Sends spawn message for scene objects and other visible objects to the given player if it has a character

Declaration
public void SpawnVisibleObjects(INetworkPlayer player, bool ignoreHasCharacter, NetworkIdentity skip)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerThe player to spawn objects for
System.BooleanignoreHasCharacterIf true will spawn visibile objects even if player does not have a spawned character yet
Mirage.NetworkIdentityskipNetworkIdentity to skip when spawning. Can be null

SpawnVisibleObjects(INetworkPlayer, Boolean, HashSet<NetworkIdentity>)

Sends spawn message for scene objects and other visible objects to the given player if it has a character

Declaration
public void SpawnVisibleObjects(INetworkPlayer player, bool ignoreHasCharacter, HashSet<NetworkIdentity> skip)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerThe player to spawn objects for
System.BooleanignoreHasCharacterIf true will spawn visibile objects even if player does not have a spawned character yet
System.Collections.Generic.HashSet<Mirage.NetworkIdentity>skipNetworkIdentity to skip when spawning. Can be null