Class NetworkSpawnManager
Class that handles object spawning
Inherited Members
Namespace: Unity.Netcode
Assembly: Unity.Netcode.Runtime.dll
Syntax
public class NetworkSpawnManager
  Fields
OwnershipToObjectsTable
Use to get all NetworkObjects owned by a client Ownership to Objects Table Format: [ClientId][NetworkObjectId][NetworkObject] Server: Keeps track of all clients' ownership Client: Keeps track of only its ownership
Declaration
public readonly Dictionary<ulong, Dictionary<ulong, NetworkObject>> OwnershipToObjectsTable
  Field Value
| Type | Description | 
|---|---|
| Dictionary<ulong, Dictionary<ulong, NetworkObject>> | 
SpawnedObjects
The currently spawned objects
Declaration
public readonly Dictionary<ulong, NetworkObject> SpawnedObjects
  Field Value
| Type | Description | 
|---|---|
| Dictionary<ulong, NetworkObject> | 
SpawnedObjectsList
A list of the spawned objects
Declaration
public readonly HashSet<NetworkObject> SpawnedObjectsList
  Field Value
| Type | Description | 
|---|---|
| HashSet<NetworkObject> | 
Properties
NetworkManager
Gets the NetworkManager associated with this SpawnManager.
Declaration
public NetworkManager NetworkManager { get; }
  Property Value
| Type | Description | 
|---|---|
| NetworkManager | 
Methods
GetClientOwnedObjects(ulong)
Returns a list of all NetworkObjects that belong to a client.
Declaration
public List<NetworkObject> GetClientOwnedObjects(ulong clientId)
  Parameters
| Type | Name | Description | 
|---|---|---|
| ulong | clientId | the client's id LocalClientId  | 
      
Returns
| Type | Description | 
|---|---|
| List<NetworkObject> | returns the list of NetworkObjects owned by the client  | 
      
GetLocalPlayerObject()
Returns the local player object or null if one does not exist
Declaration
public NetworkObject GetLocalPlayerObject()
  Returns
| Type | Description | 
|---|---|
| NetworkObject | The local player object or null if one does not exist  | 
      
GetPlayerNetworkObject(ulong)
Returns the player object with a given clientId or null if one does not exist. This is only valid server side.
Declaration
public NetworkObject GetPlayerNetworkObject(ulong clientId)
  Parameters
| Type | Name | Description | 
|---|---|---|
| ulong | clientId | the client identifier of the player  | 
      
Returns
| Type | Description | 
|---|---|
| NetworkObject | The player object with a given clientId or null if one does not exist  | 
      
InstantiateAndSpawn(NetworkObject, ulong, bool, bool, bool, Vector3, Quaternion)
Use this method to easily instantiate and spawn an instance of a network prefab. InstantiateAndSpawn will:
- Find any override associated with the NetworkObject prefab
- If there is no override, then the current NetworkObject prefab type is used.
 
 - Create an instance of the NetworkObject prefab (or its override).
 - Spawn the NetworkObject prefab instance
 
Declaration
public NetworkObject InstantiateAndSpawn(NetworkObject networkPrefab, ulong ownerClientId = 0, bool destroyWithScene = false, bool isPlayerObject = false, bool forceOverride = false, Vector3 position = default, Quaternion rotation = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| NetworkObject | networkPrefab | The NetworkObject of the pefab asset.  | 
      
| ulong | ownerClientId | The owner of the NetworkObject instance (defaults to server).  | 
      
| bool | destroyWithScene | Whether the NetworkObject instance will be destroyed when the scene it is located within is unloaded (default is false).  | 
      
| bool | isPlayerObject | Whether the NetworkObject instance is a player object or not (default is false).  | 
      
| bool | forceOverride | Whether you want to force spawning the override when running as a host or server or if you want it to spawn the override for host mode and the source prefab for server. If there is an override, clients always spawn that as opposed to the source prefab (defaults to false).  | 
      
| Vector3 | position | The starting poisiton of the NetworkObject instance.  | 
      
| Quaternion | rotation | The starting rotation of the NetworkObject instance.  | 
      
Returns
| Type | Description | 
|---|---|
| NetworkObject | The newly instantiated and spawned NetworkObject prefab instance.  |