Use Multiplayer Widgets to create and join a session
To start a multiplayer game, the host must create a session that other players can join. A session connects a group of players during a multiplayer game. Clients can use a join code to join an existing session.
Use the following multiplayer widgets to create, join, or create and join a session:
- Join Session by Code: Use a join code to join an open session.
- Join Session by Matchmaker:
- Quick Join Session: Join an open session or create a new session if no open session exists.
- Create Session: Create and automatically join a session.
- Session List: Display open sessions that you can join.
Note
When you create multiple multiplayer widgets, they overlap each other in the Game view. To use them, move each multiplayer widget UI element to another area of the canvas.
When a player joins a session, the Console window displays a log message that contains the text Joined Session
.
To use a multiplayer widget to create a new session, refer to Configure a session.
To learn more about how Unity Gaming Services use sessions, refer to Build a session with Netcode for GameObjects.
Requirements
To use a multiplayer widget to create or join a session, follow the instructions in Get started with UGS to set up your project for multiplayer services.
Create a session
Use the Create Session or Quick Join Session multiplayer widget to create a session.
Name, create, and join a session
Use the Create Session multiplayer widget to name a new session, create it, and automatically join it:
- In the Main Menu, go to GameObject > Multiplayer Widgets > Create and select Create Session.
- Enter Play mode.
- Enter a session name in the Create field.
- Select the Create button.
Automatically create and join a session
Use the Quick Join Session Multiplayer Widget to join a session without a session name or join code. If no sessions exist, this Multiplayer Widget creates one.
Note
The Matchmaker multiplayer widget also creates a session automatically. To learn how to use it, refer to Use the Matchmaker multiplayer widget.
To add a Quick Join Session Multiplayer Widget to a new scene:
- In the Main Menu, select GameObject > Multiplayer Widgets> Join and Leave > Quick Join Session.
- Save the current scene and name it Quick Join Start.
To use the Quick Join Session Multiplayer Widget:
- Enter Play mode.
- In the Game View, select the Quick Join button.
Note
Multiplayer widgets that access a session only activate when the player joins a session. For information about multiplayer widget activation, refer to Learn how multiplayer widgets work on the client and host.
Join a session
Use the Session List or Join Session by Code multiplayer widget to join a session that a host creates.
Note
You can also use the Matchmaker multiplayer widget to join a session that has multiple players. To learn how to use it, refer to Use the Matchmaker multiplayer widget.
Join a session from a session list
When one or more sessions exist, use the Session List multiplayer widget to display them all and choose a session to join:
- In the Main Menu, go to GameObject > Multiplayer Widgets > Join and Leave and select Session List.
- Go to Window > Multiplayer > Multiplayer Play Mode.
- In the Multiplayer Play Mode window, enable Player 2.
- Enter Play mode.
- Create a session.
- In the Player 2 window, select Refresh List.
- When a session name appears, select it.
- Select Join.
To learn more about Multiplayer Play Mode, refer to About Multiplayer Play Mode.
Use a session code to join a session
A session code is a short string of characters that a session generates when it's created. When a session exists, use one of the following methods to locate a session code:
- Navigate to Services > Multiplayer > Sessions Viewer. The join code appears in the Session Info section.
- In the Main Menu, go to GameObject > Multiplayer Widgets > Info and select Show Session Code. The session code appears in this widget when you are in a session.
To use the session code to join a session:
- In the Main Menu, go to GameObject > Multiplayer Widgets > Join and Leave and select Join Session by Code.
- Open Multiplayer Play Mode (Window > Multiplayer > Multiplayer Play Mode).
- In the Multiplayer Play Mode window, enable Player 2.
- Enter Play mode.
- Locate the session code for the active session.
- Select the copy icon next to the session code.
- Enter the session code into the Join field.
- Click the Join button.
Note
Use the Session Player List multiplayer widget to display a list of players that exist in the same session.