This document is about: FUSION 2
SWITCH TO

Spaces


Available in the Industries Circle
Circle
Fusion XR prototyping module

Spaces

Spaces and matchmaking

Each places where users can go are called "Spaces".
An user can either join a public space or join a private space, aka a space restricted to all user who are in the same "Group".

If too much users are in a same room for a given space/group pair, additional users will still be able to connect but will be routed to a new room.

Fusion Spaces model

This logic is implemented with Fusion matchmaking capabilities.

The space and group an user wants to join are described with session properties (note: a metaverse property is also used to allow more filtering if needed, but the overall logic is the same without it). Then, as no explicit room name is provided in the start game arguments given to the runner, the matchmaking system routes the user to a session matching the space id/group id filters. If the first room created is full, another room will be created and other users will join it, allowing to handle crowded spaces without prevent further users from connecting.

Fusion Crowded Space Example

This logic is handled by the SpaceRoom class, that configure the ConnectionManager so that it uses session properties instead of a room name.

Switching groups

SpaceRoom also handle group switching: when the user wants to join a private group (or wants to leave a private group to join the public group), the SpaceRoom handles it this way:

  • it stores in the Playerprefs the requested group id
  • it stores the user current position in the PlayerPrefs (through the SceneSpawnManager component)
  • it fades out the view
  • it reloads the scenes
  • the SpaceRoom provides the ConnectionManager the group id to be used as a session property in the matchmaking API
  • during the scene loading, the user is positioned at their previous saved position, by the SceneSpawnManager component

SpaceDescription

The space id can be either set on the SpaceRoom component in the inspector, or it is possible to prepare and provide a SpaceDescription.

The SpaceDescription is a scriptable object, with the following fields:

  • spaceId : technical data field to uniquely identify each space, and to fill in the SpaceRoom component the session properties that will route the user to a proper Fusion room for this space.
  • sceneName : the Unity scene that must be loaded when a player joins this space.
  • spaceName : the name of the space. It is loaded on the panel of portals between spaces. It is not used as an id, just as a presentation text.
  • spaceDescription : a description of the space. It is loaded on the panel of portals between spaces, to explain the purpose of the target space to the user.
  • spaceParam : optional technical data. For future use, to provide parameters to a scene when several spaces use the same scene.
  • spaceSecondaryParam : optional technical data. For future use, to provide parameters to a scene when several spaces use the same scene.

Joining another space

Joining another Space is handled by the SpaceLoader component. It is possible to either provide a full SpaceDescription on it, or just a space id string for simpler needs.

To know which Unity scene to load, the SpaceLoader can either read the scene provided in its SpaceDescription field. Or, for simpler cases, it assumes the scene name is the same than the space id string directly provided.

When its SwitchScene() method is called, the space change occurs, by loading the target scene. This methods:

  • first shutdown the current Runner
  • records the requested SpaceDescription in using SpaceRoom.RegisterSpaceRequest(). The SpaceRoom space description in the incoming scene is then ignored and changed to be sure that it matches the exact SpaceDescription stored in this SpaceLoader that led to it. This is not needed for simple spaces configurations like the one in the current sample state, but it can enable more advanced scenarios where a single Unity scene is used for several spaces.
  • then load the new Unity Scene.

C#

private async void SwitchScene()
{
...
    await runner.Shutdown(true);
    Debug.Log("Loading new scene " + SceneName);
    SpaceRoom.RegisterSpaceRequest(spaceDescription);
    SceneManager.LoadScene(SceneName, LoadSceneMode.Single);
}

Spawn point when coming from another space

The SpaceLoader component can also provide a returnPosition if autoRegisterAsReturnPoint is true, to differentiate the player spawn position when the hub scene is loaded directly and when the player come back after joining another scene.

When an user is joining the current scene (associated to Space A), just after being in the space (Space B) targeted by a SpaceLoader, the user will spawn at the returnPosition transform associated to this SpaceLoader leading to Space B. This is done by providing this return position associated to Space B to the SceneSpawnManager, which handles the user spawn position.

Dependencies

  • ConnexionManager addon

Demo

To illustrate the usage, demo scenes can be found in Assets\Photon\FusionAddons\Spaces\Demo\Scenes\ folder.

Each scene contains two portals and each portal loads a new Space when the player enter into it thanks to the SpaceLoader component.
Also, the PortalSpaceDescriptionLoader script displays the Space properties on the portal panel.

Fusion Industries Addon Spaces

Download

This addon latest version is included into the Industries addon project

Supported topologies

  • shared mode

Changelog

  • Version 2.0.0: Fusion 2.0 support
  • Version 1.0.3: Change demo scripts name
  • Version 1.0.2: Fix because of ConnectionManager namespace modification
  • Version 1.0.1: Add demo scene + add namespace
  • Version 1.0.0: First release
Back to top