Class NetSessionContext

Network session context managing replication scope.

A session context can operate in different modes: - Lobby: No scene, pure IReflectable replication only - ActiveScene: Scene-based replication with SceneObjects - Transitioning: Scene change in progress, replication paused

Example usage:

The session context defines the scope of replication for a NetSession. It manages the association between the session and optional SceneInstance, and provides access to the replication manager.

Hierarchy

  • FrameworkObject
    • NetSessionContext

Constructors

  • Parameters

    • OptionalisInternalConstructor: boolean

    Returns NetSessionContext

Accessors

  • get activeScene(): SceneInstance
  • Returns the currently active scene instance.

    Returns SceneInstance

    The active scene, or nullptr if in Lobby mode.

  • get gameState(): Resource
  • Sets the current game state. The game state is shared across all connected clients. The host has full authority over the game state.

    Returns Resource

    The state can only be set by a host session.

  • set gameState(value): void
  • Sets the current game state. The game state is shared across all connected clients. The host has full authority over the game state.

    Parameters

    Returns void

    The state can only be set by a host session.

  • get isReplicationPaused(): boolean
  • Returns true if replication is currently paused.

    Returns boolean

    True if in Transitioning mode or otherwise paused.

  • get localConnectionId(): number
  • Returns the local connection ID for this session.

    Returns number

    The local connection ID from the session manager.

  • get sceneNodeManager(): SceneNodeManager
  • Returns the SceneNodeManager for the active scene.

    Returns SceneNodeManager

    The object manager, or nullptr if no scene is active.

    Used by the replication manager for SceneObject snapshot management.

  • get sceneTransitionId(): number
  • Sets the scene transition ID.

    Returns number

    On host: Call with an incremented value before BeginSceneTransition. On client: Call with the ID received from the host's SceneLoadRequest. This ensures both sides have the same ID for message validation.

  • set sceneTransitionId(value): void
  • Parameters

    • value: number

    Returns void

Methods

  • Gets the game state for the specified connection.

    The game state is shared across all connected clients. The host has full authority over the game state.

    Parameters

    • connectionId: number

    Returns Resource

    On clients, the connect id of the current client should be used to get its player state.

  • Returns true if the context has an active scene.

    Returns boolean

    True if in ActiveScene mode with a valid scene.

  • Sets the player state for a specific connection. The player state is specific to each connected client. The host has full authority over all player states.

    Parameters

    • playerState: Resource | ResourceHandle<Resource>

      The new player state to set.

    • connectionId: number

      The connection ID of the player whose state is being set.

    Returns boolean

    True if the player state was successfully set.

    The state can only be set by a host session.

Events

onModeChanged: Event<[oldMode: EnumValue<NetSessionMode, number>, newMode: EnumValue<NetSessionMode, number>], void>

Event triggered when the session mode changes.

Previous mode.

New mode.

onSceneTransitionBegin: Event<[scene: SceneInstance], void>

Event triggered when a scene transition begins.

The scene being transitioned to.

onSceneTransitionComplete: Event<[scene: SceneInstance], void>

Event triggered when a scene transition completes.

The now-active scene.

onSceneCleared: Event<[], void>

Event triggered when the scene is cleared.

onObjectReplicated: Event<[object: number], void>

Event triggered when an object is replicated (state applied). Client only.

The replicated object.