Class NetworkManager
Acts as a container for all things related to your networking session.
Inheritance
Inherited Members
Namespace: FishNet.Managing
Assembly: FishNet.Runtime.dll
Syntax
[DefaultExecutionOrder(-32768)]
[DisallowMultipleComponent]
[AddComponentMenu("FishNet/Manager/NetworkManager")]
public sealed class NetworkManager : MonoBehaviour
Fields
FISHNET_VERSION
Version of this release.
Declaration
public const string FISHNET_VERSION = "4.4.7"
Field Value
Type | Description |
---|---|
System.String |
Properties
ClientManager
ClientManager for this NetworkManager.
Declaration
public ClientManager ClientManager { get; }
Property Value
Type | Description |
---|---|
ClientManager |
DebugManager
DebugManager for this NetworkManager.
Declaration
public DebugManager DebugManager { get; }
Property Value
Type | Description |
---|---|
DebugManager |
Initialized
True if this instance of the NetworkManager is initialized.
Declaration
public bool Initialized { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Instances
Currently initialized NetworkManagers.
Declaration
public static IReadOnlyList<NetworkManager> Instances { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<NetworkManager> |
IsClient
Declaration
[Obsolete("Use IsClientStarted. Note the difference between IsClientInitialized and IsClientStarted.")]
public bool IsClient { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsClientOnly
Declaration
[Obsolete("Use IsClientOnlyStarted. Note the difference between IsClientOnlyInitialized and IsClientOnlyStarted.")]
public bool IsClientOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsClientOnlyStarted
True if only the client is started and authenticated.
Declaration
public bool IsClientOnlyStarted { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsClientStarted
True if the client is started and authenticated.
Declaration
public bool IsClientStarted { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsHost
Declaration
[Obsolete("Use IsHostStarted. Note the difference between IsHostInitialized and IsHostStarted.")]
public bool IsHost { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsHostStarted
True if client and server are started.
Declaration
public bool IsHostStarted { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsOffline
True if client nor server are started.
Declaration
public bool IsOffline { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsServer
Declaration
[Obsolete("Use IsServerStarted. Note the difference between IsServerInitialized and IsServerStarted.")]
public bool IsServer { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsServerOnly
Declaration
[Obsolete("Use IsServerOnlyStarted. Note the difference between IsServerOnlyInitialized and IsServerOnlyStarted.")]
public bool IsServerOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsServerOnlyStarted
True if only the server is started.
Declaration
public bool IsServerOnlyStarted { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsServerStarted
True if server is started.
Declaration
public bool IsServerStarted { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
ObjectPool
Object pool to use for this NetworkManager. Value may be null.
Declaration
public ObjectPool ObjectPool { get; }
Property Value
Type | Description |
---|---|
FishNet.Utility.Performance.ObjectPool |
ObserverManager
ObserverManager for this NetworkManager.
Declaration
public ObserverManager ObserverManager { get; }
Property Value
Type | Description |
---|---|
ObserverManager |
RollbackManager
RollbackManager for this NetworkManager.
Declaration
public RollbackManager RollbackManager { get; }
Property Value
Type | Description |
---|---|
RollbackManager |
RuntimeSpawnablePrefabs
Collection to use for spawnable objects added at runtime, such as addressables.
Declaration
public IReadOnlyDictionary<ushort, PrefabObjects> RuntimeSpawnablePrefabs { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyDictionary<System.UInt16, FishNet.Managing.Object.PrefabObjects> |
SceneManager
SceneManager for this NetworkManager.
Declaration
public SceneManager SceneManager { get; }
Property Value
Type | Description |
---|---|
SceneManager |
ServerManager
ServerManager for this NetworkManager.
Declaration
public ServerManager ServerManager { get; }
Property Value
Type | Description |
---|---|
ServerManager |
SpawnablePrefabs
Collection to use for spawnable objects.
Declaration
public PrefabObjects SpawnablePrefabs { get; set; }
Property Value
Type | Description |
---|---|
FishNet.Managing.Object.PrefabObjects |
StatisticsManager
StatisticsManager for this NetworkManager.
Declaration
public StatisticsManager StatisticsManager { get; }
Property Value
Type | Description |
---|---|
StatisticsManager |
TimeManager
TimeManager for this NetworkManager.
Declaration
public TimeManager TimeManager { get; }
Property Value
Type | Description |
---|---|
TimeManager |
TransportManager
TransportManager for this NetworkManager.
Declaration
public TransportManager TransportManager { get; }
Property Value
Type | Description |
---|---|
TransportManager |
Methods
CacheObjects(NetworkObject, Int32, Boolean)
Instantiates a number of objects and adds them to the pool.
Declaration
public void CacheObjects(NetworkObject prefab, int count, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | prefab | Prefab to cache. |
System.Int32 | count | Quantity to spawn. |
System.Boolean | asServer | True if storing prefabs for the server collection. This is only applicable when using DualPrefabObjects. |
GetInstance<T>()
Returns class of type from registered instances. A warning will display if not found.
Declaration
public T GetInstance<T>()
where T : Component
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T | Type to get. |
GetPooledInstantiated(NetworkObject, Boolean)
Returns an instantiated or pooled object using supplied values. When a value is not specified it uses default values to the prefab or NetworkManager.
Declaration
public NetworkObject GetPooledInstantiated(NetworkObject prefab, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | prefab | |
System.Boolean | asServer |
Returns
Type | Description |
---|---|
NetworkObject |
GetPooledInstantiated(NetworkObject, Transform, Boolean)
Returns an instantiated or pooled object using supplied values. When a value is not specified it uses default values to the prefab or NetworkManager.
Declaration
public NetworkObject GetPooledInstantiated(NetworkObject prefab, Transform parent, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | prefab | |
UnityEngine.Transform | parent | |
System.Boolean | asServer |
Returns
Type | Description |
---|---|
NetworkObject |
GetPooledInstantiated(NetworkObject, Vector3, Quaternion, Boolean)
Returns an instantiated or pooled object using supplied values. When a value is not specified it uses default values to the prefab or NetworkManager.
Declaration
public NetworkObject GetPooledInstantiated(NetworkObject prefab, Vector3 position, Quaternion rotation, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | prefab | |
UnityEngine.Vector3 | position | |
UnityEngine.Quaternion | rotation | |
System.Boolean | asServer |
Returns
Type | Description |
---|---|
NetworkObject |
GetPooledInstantiated(NetworkObject, Vector3, Quaternion, Transform, Boolean)
Returns an instantiated or pooled object using supplied values. When a value is not specified it uses default values to the prefab or NetworkManager.
Declaration
public NetworkObject GetPooledInstantiated(NetworkObject prefab, Vector3 position, Quaternion rotation, Transform parent, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | prefab | |
UnityEngine.Vector3 | position | |
UnityEngine.Quaternion | rotation | |
UnityEngine.Transform | parent | |
System.Boolean | asServer |
Returns
Type | Description |
---|---|
NetworkObject |
GetPooledInstantiated(Int32, UInt16, ObjectPoolRetrieveOption, Transform, Nullable<Vector3>, Nullable<Quaternion>, Nullable<Vector3>, Boolean)
Returns an instantiated or pooled object using supplied values. When a value is not specified it uses default values to the prefab or NetworkManager.
Declaration
public NetworkObject GetPooledInstantiated(int prefabId, ushort collectionId, ObjectPoolRetrieveOption options, Transform parent, Vector3? position, Quaternion? rotation, Vector3? scale, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | prefabId | |
System.UInt16 | collectionId | |
FishNet.Utility.Performance.ObjectPoolRetrieveOption | options | |
UnityEngine.Transform | parent | |
System.Nullable<UnityEngine.Vector3> | position | |
System.Nullable<UnityEngine.Quaternion> | rotation | |
System.Nullable<UnityEngine.Vector3> | scale | |
System.Boolean | asServer |
Returns
Type | Description |
---|---|
NetworkObject |
GetPooledInstantiated(Int32, UInt16, Boolean)
Returns an instantiated or pooled object using supplied values. When a value is not specified it uses default values to the prefab or NetworkManager.
Declaration
public NetworkObject GetPooledInstantiated(int prefabId, ushort collectionId, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | prefabId | |
System.UInt16 | collectionId | |
System.Boolean | asServer |
Returns
Type | Description |
---|---|
NetworkObject |
GetPooledInstantiated(Int32, UInt16, Transform, Nullable<Vector3>, Nullable<Quaternion>, Nullable<Vector3>, Boolean, Boolean)
Returns an instantiated or pooled object using supplied values. When a value is not specified it uses default values to the prefab or NetworkManager.
Declaration
[Obsolete("Use GetPooledInstantiated(int, ushort, RetrieveOption, parent, Vector3?, Quaternion? Vector3?, bool) instead.")]
public NetworkObject GetPooledInstantiated(int prefabId, ushort collectionId, Transform parent, Vector3? position, Quaternion? rotation, Vector3? scale, bool makeActive, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | prefabId | |
System.UInt16 | collectionId | |
UnityEngine.Transform | parent | |
System.Nullable<UnityEngine.Vector3> | position | |
System.Nullable<UnityEngine.Quaternion> | rotation | |
System.Nullable<UnityEngine.Vector3> | scale | |
System.Boolean | makeActive | True to make the NetworkObject active if not already. Using false will not prevent an object from activating via instantation, but rather indicates to not set active manually prior to returning a NetworkObject. |
System.Boolean | asServer |
Returns
Type | Description |
---|---|
NetworkObject |
GetPooledInstantiated(Int32, UInt16, Vector3, Quaternion, Boolean)
Returns an instantiated or pooled object using supplied values. When a value is not specified it uses default values to the prefab or NetworkManager.
Declaration
public NetworkObject GetPooledInstantiated(int prefabId, ushort collectionId, Vector3 position, Quaternion rotation, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | prefabId | |
System.UInt16 | collectionId | |
UnityEngine.Vector3 | position | |
UnityEngine.Quaternion | rotation | |
System.Boolean | asServer |
Returns
Type | Description |
---|---|
NetworkObject |
GetPooledInstantiated(GameObject, Boolean)
Returns an instantiated or pooled object using supplied values. When a value is not specified it uses default values to the prefab or NetworkManager.
Declaration
public NetworkObject GetPooledInstantiated(GameObject prefab, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.GameObject | prefab | |
System.Boolean | asServer |
Returns
Type | Description |
---|---|
NetworkObject |
GetPooledInstantiated(GameObject, Transform, Boolean)
Returns an instantiated or pooled object using supplied values. When a value is not specified it uses default values to the prefab or NetworkManager.
Declaration
public NetworkObject GetPooledInstantiated(GameObject prefab, Transform parent, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.GameObject | prefab | |
UnityEngine.Transform | parent | |
System.Boolean | asServer |
Returns
Type | Description |
---|---|
NetworkObject |
GetPooledInstantiated(GameObject, Vector3, Quaternion, Boolean)
Returns an instantiated or pooled object using supplied values. When a value is not specified it uses default values to the prefab or NetworkManager.
Declaration
public NetworkObject GetPooledInstantiated(GameObject prefab, Vector3 position, Quaternion rotation, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.GameObject | prefab | |
UnityEngine.Vector3 | position | |
UnityEngine.Quaternion | rotation | |
System.Boolean | asServer |
Returns
Type | Description |
---|---|
NetworkObject |
GetPooledInstantiated(GameObject, Vector3, Quaternion, Transform, Boolean)
Returns an instantiated or pooled object using supplied values. When a value is not specified it uses default values to the prefab or NetworkManager.
Declaration
public NetworkObject GetPooledInstantiated(GameObject prefab, Vector3 position, Quaternion rotation, Transform parent, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.GameObject | prefab | |
UnityEngine.Vector3 | position | |
UnityEngine.Quaternion | rotation | |
UnityEngine.Transform | parent | |
System.Boolean | asServer |
Returns
Type | Description |
---|---|
NetworkObject |
GetPrefab(Int32, Boolean)
Returns a prefab with prefabId. This method will bypass object pooling.
Declaration
public NetworkObject GetPrefab(int prefabId, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | prefabId | PrefabId to get. |
System.Boolean | asServer | True if getting the prefab asServer. |
Returns
Type | Description |
---|---|
NetworkObject |
GetPrefabIndex(GameObject, Boolean)
Gets the index a prefab uses. Can be used in conjuction with GetPrefab.
Declaration
public int GetPrefabIndex(GameObject prefab, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.GameObject | prefab | |
System.Boolean | asServer | True if to get from the server collection. |
Returns
Type | Description |
---|---|
System.Int32 | Returns index if found, and -1 if not found. |
GetPrefabObjects<T>(UInt16, Boolean)
Gets the PrefabObjects to use for spawnableCollectionId.
Declaration
public PrefabObjects GetPrefabObjects<T>(ushort spawnableCollectionId, bool createIfMissing)
where T : PrefabObjects
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | spawnableCollectionId | Id to use. 0 will return the configured SpawnablePrefabs. |
System.Boolean | createIfMissing | True to create and assign a PrefabObjects if missing for the collectionId. |
Returns
Type | Description |
---|---|
FishNet.Managing.Object.PrefabObjects |
Type Parameters
Name | Description |
---|---|
T | Type of PrefabObjects to return. This is also used to create an instance of type when createIfMissing is true. |
HasInstance<T>()
Returns if an instance exists for type.
Declaration
public bool HasInstance<T>()
where T : Component
Returns
Type | Description |
---|---|
System.Boolean |
Type Parameters
Name | Description |
---|---|
T | Type to check. |
RegisterInstance<T>(T, Boolean)
Registers a new component to this NetworkManager.
Declaration
public void RegisterInstance<T>(T component, bool replace = true)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
T | component | Reference of the component being registered. |
System.Boolean | replace | True to replace existing references. |
Type Parameters
Name | Description |
---|---|
T | Type to register. |
RegisterInvokeOnInstance<T>(Action<Component>)
Invokes an action when a specified component becomes registered. Action will invoke immediately if already registered.
Declaration
public void RegisterInvokeOnInstance<T>(Action<Component> handler)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
System.Action<UnityEngine.Component> | handler | Action to invoke. |
Type Parameters
Name | Description |
---|---|
T | Component type. |
RemoveSpawnableCollection(UInt16)
Removes the PrefabObjects collection from memory. This should only be called after you properly disposed of it's contents properly.
Declaration
public bool RemoveSpawnableCollection(ushort spawnableCollectionId)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | spawnableCollectionId | CollectionId to remove. |
Returns
Type | Description |
---|---|
System.Boolean | True if collection was found and removed. |
StorePooledInstantiated(NetworkObject, Boolean)
Stores an instantied object.
Declaration
public void StorePooledInstantiated(NetworkObject instantiated, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | instantiated | Object which was instantiated. |
System.Boolean | asServer | True to store for the server. |
TryGetInstance<T>(out T)
Returns class of type from registered instances.
Declaration
public bool TryGetInstance<T>(out T result)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
T | result |
Returns
Type | Description |
---|---|
System.Boolean | True if was able to get instance. |
Type Parameters
Name | Description |
---|---|
T | Type to get. |
TryRegisterInstance<T>(T)
Tries to registers a new component to this NetworkManager. This will not register the instance if another already exists.
Declaration
public bool TryRegisterInstance<T>(T component)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
T | component | Reference of the component being registered. |
Returns
Type | Description |
---|---|
System.Boolean | True if was able to register, false if an instance is already registered. |
Type Parameters
Name | Description |
---|---|
T | Type to register. |
UnregisterInstance<T>()
Unregisters a component from this NetworkManager.
Declaration
public void UnregisterInstance<T>()
where T : Component
Type Parameters
Name | Description |
---|---|
T | Type to unregister. |
UnregisterInvokeOnInstance<T>(Action<Component>)
Removes an action to be invokes when a specified component becomes registered.
Declaration
public void UnregisterInvokeOnInstance<T>(Action<Component> handler)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
System.Action<UnityEngine.Component> | handler | Action to invoke. |
Type Parameters
Name | Description |
---|---|
T | Component type. |