Skip to main content
Supported on
Snapchat

Multiplayer Manager

MultiplayerManager is the entry point for the Connected Framework. Add one to your scene, give it a ConnectedLensModule asset, and it configures matchmaking and drives the Lens through its connection states.

Every other Connected Framework component depends on it. If a Sync Entity never becomes ready, the usual cause is a missing or unconfigured Multiplayer Manager.

Component Inputs

NameTypeDescription
Connected LensConnectedLensModuleThe Connected Lens module asset the session runs on. Required.
Singleplayer Mode"mocked" or "manual"Mocked Online simulates a multiplayer session while disconnected, which lets you use framework features in singleplayer. When starting a real session afterwards, existing Sync Entities need to be recreated. Defaults to Mocked Online.
Retry AttemptsintNumber of times to retry connecting. Connecting can fail from network errors, no players found, or other issues. Set to 0 to disable retries. Defaults to 3.
Disconnect Behavior"keep_current_state" or "singleplayer"What to do when disconnected. Keep current state leaves the state unchanged; Switch to Singleplayer returns to singleplayer. Mocked mode is restored either way if enabled. Defaults to Switch to Singleplayer.
Auto Start If Chat DrawerbooleanIf enabled, the session starts automatically when the Lens is launched from a DM or group chat, joining the users in that chat and skipping singleplayer. Never triggers inside the editor. Defaults to true.
Matchmaking
Min PlayersintMinimum players required to start the match. Lowest allowed value is 1. Defaults to 2.
Max PlayersintMaximum players allowed in the match. Highest allowed value is 64, and it must be at least 2 and greater than or equal to Min Players. Defaults to 4.
Target PlayersintTarget number of players matchmaking attempts to fill. Must be between Min and Max Players. Defaults to 2.
Debug Options
Editor Start OnlinebooleanStarts the multiplayer session automatically on Lens load, skipping singleplayer. Only effective inside the editor. Defaults to false.
Editor Extra Search TimeintSet greater than 0 to simulate additional matchmaking wait time, in seconds. Editor only. Defaults to 0.
Editor Session Type"chat_drawer" or "matchmaking"Session type used inside the editor, where the launch context cannot be detected. Defaults to Matchmaking.
Debug TextText (optional)Optional text component for on-screen connection state.
Logger ConfigLoggerConfigLog level configuration for the framework.

The matchmaking timeout is controlled by the backend, not by this component. The framework carries an estimate used only for driving UI, such as a progress bar.

Component API

Get the singleton with MultiplayerManager.getInstance(), or from the scene component with getMultiplayerManager().

Name (signature)Description
playOnline(retryAttempts?: number): Promise<void>Starts matchmaking and connects to a session. Defaults to the component's Retry Attempts.
getState(): MultiplayerStateCurrent state: initializing, singleplayer, searching_session, or multiplayer.
getSessionType(): SessionTypeWhether this session came from chat_drawer or matchmaking.
getMinPlayers(): numberConfigured minimum players.
getMaxPlayers(): numberConfigured maximum players.
getTargetPlayers(): numberConfigured target players.
getSessionController(): SessionControllerThe underlying Session Controller.
waitForReady(): Promise<void>Resolves once the manager has finished configuring.

Events

NameCalled withDescription
onStateChangenewState, previousStateFires on every state transition.
onSingleplayerStartnoneThe Lens entered singleplayer.
onSearchingSessionStartnoneMatchmaking search began.
onMultiplayerStartnoneA multiplayer session is live.
onRetryremainingAttempts, totalAttemptsA retriable failure occurred and a retry is being attempted.
onRetriesExhaustedlastErrorA retriable failure used up every attempt. Terminal failures do not fire this.
onMatchmakingRejectedByClienterrorMatchmaking was rejected by the client. Retries are not attempted.
onPlayOnlineFailederrorConnecting failed for any reason, whether retries were exhausted or the failure was terminal.

onSingleplayerStart, onSearchingSessionStart, and onMultiplayerStart are state-change events: if the state is already active when you subscribe, your callback runs immediately. That makes them safe to attach during onAwake without racing the connection.

Usage

import { MultiplayerManager } from 'ConnectedFramework.lspkg/Components/MultiplayerManager';

@component
export class PlayOnlineButton extends BaseScriptComponent {
onAwake() {
const manager = MultiplayerManager.getInstance();

manager.onSearchingSessionStart.add(() => {
print('Searching for players');
});

manager.onMultiplayerStart.add(() => {
print('Match started');
});

manager.onPlayOnlineFailed.add((error) => {
print(`Could not connect: ${error}`);
});
}

startMatch() {
MultiplayerManager.getInstance()
.playOnline()
.catch((error) => print(`playOnline failed: ${error}`));
}
}

Testing in the editor

The Debug Options exist because the editor cannot detect a real launch context:

  • Editor Start Online skips singleplayer so you land straight in a session.
  • Editor Extra Search Time lets you see your matchmaking UI for long enough to check it, instead of the search resolving instantly.
  • Editor Session Type decides whether the editor behaves like a chat launch or a matchmaking launch.

To test with more than one player, open a second Preview panel. Each Preview panel connects as its own participant.

Was this page helpful?
Yes
No