Legacy Documentation: Version 5.1
Matchmaker
Converting a Single Player Game to Multiplayer

Scene Objects

Objects that are created dynamically are added to the network with NetworkServer.Spawn(), but objects that already exist in the scene are handled differently. These objects are loaded with the scene on both the client and server, and exist at runtime before any spawn messages are sent.

All objects in the scene with a NetworkIdentity component will be disabled when the scene is loaded; on both the client and the server. Then, when the scene is fully loaded, NetworkServer.SpawnObjects() is called to activate these networked scene objects. This will be done automatically by the NetworkManager when the server scene finishes loading - or can be called directly by user code. This causes the networked scene objects to be spawned in a special way - the existing instances are hooked up to the network instead of new instances being created.

There are some good reasons to use scene objects instead of dynamically spawned objects. These objects:

  • are loaded with the level, so there will be no pause at runtime
  • can have specific modifications that differ from prefabs
  • can be referenced by other object instances in the scene, which can avoid finding the objects to hook them up at runtime

Once scene objects have been spawned by NetworkServer.SpawnObjects() then they behave like every other spawned objects. Updates will be sent, and ClientRPC calls can be made.

If an object in scene is destroyed on the server before a client joins the game, then it will never be spawned on new clients that join.

Matchmaker
Converting a Single Player Game to Multiplayer