Method AddNetworkPrefab
AddNetworkPrefab(GameObject)
Adds a new prefab to the network prefab list. This can be any GameObject with a NetworkObject component, from any source (addressables, asset bundles, Resource.Load, dynamically created, etc)
There are three limitations to this method:
- If you have NetworkConfig.ForceSamePrefabs enabled, you can only do this before starting networking, and the server and all connected clients must all have the same exact set of prefabs added via this method before connecting
- Adding a prefab on the server does not automatically add it on the client - it's up to you to make sure the client and server are synchronized via whatever method makes sense for your game (RPCs, configurations, deterministic loading, etc)
- If the server sends a Spawn message to a client that has not yet added a prefab for, the spawn message and any other relevant messages will be held for a configurable time (default 1 second, configured via NetworkConfig.SpawnTimeout) before an error is logged. This is intended to enable the SDK to gracefully handle unexpected conditions (slow disks, slow network, etc) that slow down asset loading. This timeout should not be relied on and code shouldn't be written around it - your code should be written so that the asset is expected to be loaded before it's needed.
Declaration
public void AddNetworkPrefab(GameObject prefab)
Parameters
Type | Name | Description |
---|---|---|
GameObject | prefab |
Exceptions
Type | Condition |
---|---|
Exception |