Spawning and Despawning
For objects to exist over the network they must have a NetworkObject component on them, and must be spawned using the server. To spawn an object it must first be instantiated, and then passed into a Spawn method. There are a variety of Spawn methods to access for your convenience, all of which provide the same outcome.
Networked addressable prefabs must be registered with the NetworkManager differently. See Addressables guide for more information on this.
Spawning Without an Owner is done by passing in null for the owner, or simply leaving the argument out.
Spawning With Ownership
You may also access the spawn method within any script that inherits NetworkBehaviour, or by accessing the NetworkObject.
Despawning can be accessed the same ways as spawning. Through a NetworkBehaviour script, a reference NetworkObject, or through the ServerManager directly.
When despawning you may also choose to pool the object rather than destroy it. There are optional parameters available to change this behavior.
You can check if an object is spawned at anytime using the IsSpawned property within NetworkBehaviour, or NetworkObject.
Scene Objects are spawned and despawned like instantiated objects, except you pass in the reference of the already instantiated/placed scene object. A scene object becomes disabled rather than destroyed when despawned.
Last updated