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, Network |
SpawnedObjects
The currently spawned objects
Declaration
public readonly Dictionary<ulong, NetworkObject> SpawnedObjects
Field Value
Type | Description |
---|---|
Dictionary<ulong, Network |
SpawnedObjectsList
A list of the spawned objects
Declaration
public readonly HashSet<NetworkObject> SpawnedObjectsList
Field Value
Type | Description |
---|---|
Hash |
Properties
NetworkManager
Gets the NetworkManager associated with this SpawnManager.
Declaration
public NetworkManager NetworkManager { get; }
Property Value
Type | Description |
---|---|
Network |
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 Local |
Returns
Type | Description |
---|---|
List<Network |
returns the list of Network |
GetLocalPlayerObject()
Returns the local player object or null if one does not exist
Declaration
public NetworkObject GetLocalPlayerObject()
Returns
Type | Description |
---|---|
Network |
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 |
---|---|
Network |
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 Network
Object prefab- If there is no override, then the current Network
Object prefab type is used.
- If there is no override, then the current Network
- Create an instance of the Network
Object prefab (or its override). - Spawn the Network
Object 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 |
---|---|---|
Network |
networkPrefab | The Network |
ulong | ownerClientId | The owner of the Network |
bool | destroyWithScene | Whether the Network |
bool | isPlayerObject | Whether the Network |
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 Network |
Quaternion | rotation | The starting rotation of the Network |
Returns
Type | Description |
---|---|
Network |
The newly instantiated and spawned Network |