Mirror
Search…
⌃K

Scene

Scene Interest Management

Scene Interest Management

Scene Interest Management is used with Additive Scenes to networked objects to subscenes with physics isolation. That means that even if you have several instances of the same subscene loaded on the server, collisions and such between objects only happen within that subscene without interfering with others.
Server and connected clients always have the same main scene loaded. With additive scenes, this is typically a container scene, and additive subscenes have the actual scene contents.

Setting Up

Add the Scene Interest Management component to the same object as your Network Manager:
In each subscene, add an empty game object, and add a Physics Simulator component to that. Since additive scenes will be loaded on the server as "physics scenes" Unity doesn't simulate physics for them, so this component does that for you in each subscene.
Also in each subscene, create an empty game object called Environment with a Network Identity and make all static non-networked content to be children of this object. Typically this would include scenery, such as buildings, road meshes and other non-interactive content.
Do not put anything under the Environment object that will be networked and/or may be interactive by players, e.g. doors, pickups, kiosks, etc.
When you instantiate a player or other networked object, Unity doesn't have any built-in mechanism to specify which subscene the object is instantiated to...it's always the active scene, which is our container scene. After instantiating and before spawning the object, call SceneManager.MoveGameObjectToScene to move the object into the correct subscene. Once it's spawned it will be visible to clients with player objects in the same subscene. If you move it to another subscene, visibility in both the new and previous subscenes will be updated automatically.
Note that the networked objects are only moved to subscenes on the server. Clients spawn everything in the container scene, and there's no need to move objects to a subscene on the clients, since they only have one subscene loaded at a time.
Last modified 1yr ago