Class NetworkPrefabs
A class that represents the runtime aspect of network prefabs. This class contains processed prefabs from the NetworkPrefabsList, as well as additional modifications (additions and removals) made at runtime.
Inherited Members
Namespace: Unity.Netcode
Assembly: solution.dll
Syntax
[Serializable]
public class NetworkPrefabs
Fields
NetworkPrefabOverrideLinks
This dictionary provides a quick way to check and see if a NetworkPrefab has a NetworkPrefab override. Generated at runtime and OnValidate
Declaration
[NonSerialized]
public Dictionary<uint, NetworkPrefab> NetworkPrefabOverrideLinks
Field Value
Type | Description |
---|---|
Dictionary<uint, NetworkPrefab> |
NetworkPrefabsLists
Edit-time scripted object containing a list of NetworkPrefabs.
Declaration
[SerializeField]
public List<NetworkPrefabsList> NetworkPrefabsLists
Field Value
Type | Description |
---|---|
List<NetworkPrefabsList> |
Remarks
This field can be null if no prefabs are pre-configured. Runtime usages of NetworkPrefabs should not depend on this edit-time field for execution.
OverrideToNetworkPrefab
This is used for the legacy way of spawning NetworkPrefabs with an override when manually instantiating and spawning. To handle multiple source NetworkPrefab overrides that all point to the same target NetworkPrefab use InstantiateAndSpawn(NetworkObject, ulong, bool, bool, bool, Vector3, Quaternion) or InstantiateAndSpawn(NetworkManager, ulong, bool, bool, bool, Vector3, Quaternion)
Declaration
[NonSerialized]
public Dictionary<uint, uint> OverrideToNetworkPrefab
Field Value
Type | Description |
---|---|
Dictionary<uint, uint> |
Properties
Prefabs
Declaration
public IReadOnlyList<NetworkPrefab> Prefabs { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<NetworkPrefab> |
Methods
Add(NetworkPrefab)
Add a new NetworkPrefab instance to the list
Declaration
public bool Add(NetworkPrefab networkPrefab)
Parameters
Type | Name | Description |
---|---|---|
NetworkPrefab | networkPrefab |
Returns
Type | Description |
---|---|
bool |
Remarks
The framework does not synchronize this list between clients. Any runtime changes must be handled manually.
Any modifications made here are not persisted. Permanent configuration changes should be done through the NetworkPrefabsList scriptable object property.
Contains(NetworkPrefab)
Check if the given NetworkPrefab is present within the list
Declaration
public bool Contains(NetworkPrefab prefab)
Parameters
Type | Name | Description |
---|---|---|
NetworkPrefab | prefab | The prefab to check |
Returns
Type | Description |
---|---|
bool | Whether or not the prefab exists |
Contains(GameObject)
Check if the given GameObject is present as a prefab within the list
Declaration
public bool Contains(GameObject prefab)
Parameters
Type | Name | Description |
---|---|---|
GameObject | prefab | The prefab to check |
Returns
Type | Description |
---|---|
bool | Whether or not the prefab exists |
~NetworkPrefabs()
Declaration
protected ~NetworkPrefabs()
Initialize(bool)
Processes the NetworkPrefabsList if one is present for use during runtime execution, else processes Prefabs.
Declaration
public void Initialize(bool warnInvalid = true)
Parameters
Type | Name | Description |
---|---|---|
bool | warnInvalid |
Remove(NetworkPrefab)
Remove a NetworkPrefab instance from the list
Declaration
public void Remove(NetworkPrefab prefab)
Parameters
Type | Name | Description |
---|---|---|
NetworkPrefab | prefab |
Remarks
The framework does not synchronize this list between clients. Any runtime changes must be handled manually.
Any modifications made here are not persisted. Permanent configuration changes should be done through the NetworkPrefabsList scriptable object property.
Remove(GameObject)
Remove a NetworkPrefab instance with matching Prefab from the list
Declaration
public void Remove(GameObject prefab)
Parameters
Type | Name | Description |
---|---|---|
GameObject | prefab |
Remarks
The framework does not synchronize this list between clients. Any runtime changes must be handled manually.
Any modifications made here are not persisted. Permanent configuration changes should be done through the NetworkPrefabsList scriptable object property.