Loading Scenes
Last updated
Last updated
Having a simple online and offline scene is very to do through the built-in component. You can read more about using it .
Loading Scenes globally or by connection will add the specified clients connection as an to the scenes if utilizing the Scene Condition, so globally will add all clients as Observers, and by connection will only add the connections specified. - See for more info.
In the Examples below, all SceneManager calls are done inside a NetworkBehaviour class, that is why you can get reference to SceneManager by doing base.SceneManager. If you would like a reference outside of a NetworkBehaviour consider using FishNets .SceneManager.
Before calling the SceneManagers Load Scene functions you will need to setup the load data to tell the how you want it to handle the scene load.
is the class used to specify what scene you want the to load. You will not create the lookup data manually and instead use the SceneLoadData constructors that will create the SceneLookupData automatically.
When loading a scene in any way, you must pass in an instance of a class into the load methods. This class provides the scene manager all of the info it needs to load the scene or scenes properly.
The constructors available for will automatically create the needed for the SceneManager to handle if you are loading a new scene, or an existing instance of one.
When loading multiple scenes in one call, the NetworkObjects you put into will be moved to the first valid scene in the list of scenes you tried to load. See Persisting NetworkObjects for more info about keeping NetworkObjects across scenes.
If you load the scene by name, it will load the connections into the first scene found with that name. If you are utilizing , then there may be multiple scenes loaded with the same name. So be alert when loading into existing scenes by name.
You can load clients into scenes that have no other clients in them if you are utilizing - the ability to keep a scene loaded with its current state on the server when all clients leave the scene.
Replacing Scenes by Default will replace scenes on both the server and clients. If you would like the server to keep the scene loaded and only replace the scene on the clients - see for more details.
The Class has very detailed XML comments on how the load process works in detail, if you need to troubleshoot the scene load process, these comments will help you understand the flow of how a scene loads.
Make sure to check out the that you can subscribe to to give better control over your game.