Network Identity
Last updated
Last updated
The component enables you to spawn GameObjects
on the server and have them automatically appear on each client.
In order to be able to spawn and despawn a NetworkIdentity
through code, it must be a part of a game's NetworkPrefabCollection. The template project includes a collection in the Assets/Resources
folder.
If your project does not already contain a collection, you can automatically generate one through the "Generate Network Prefab Collections" menu item.
To add a NetworkIdentity
to your game's NetworkPrefabCollection, drag a prefab from your Hierarchy or Project tab onto the NetworkPrefabCollection "Network Prefabs" list, or select the prefab through the search menu.
When a player joins a game all networked GameObjects
in the server scene are automatically replicated to the player.
You can use networkIdentity.netId
to send a reference to a NetworkIdentity via NetworkSignals and NetworkFunctions.
Use NetworkUtil.GetNetworkIdentity(netId)
to retrieve a NetworkIdentity from the netId.
The NetworkIdentity
component can be added to any through the "Add Component" menu.
When a NetworkPrefabCollection is generated, it is automatically populated with every prefab in the project that contains a . For smaller projects, this tool can be used to entirely manage a game's collection. If a game has a large amount of assets, developers should opt to manually add new prefabs to their game's collection.