Multiplayer Services Building Blocks prerequisites
Set up your project to work with the Unity Services that the Unity Multiplayer Services Building Blocks use.
Read time 3 minutesLast updated 13 days ago
To use the Multiplayer Unity Building Blocks, set up the following in your project:
- A Unity project (6.0 LTS or later recommended).
- Access to Unity Dashboard and a Unity organization.
- Editor sign-in with a user that has access to the organization and project.
- Network access to Unity Services endpoints.
How Multiplayer Building Blocks work
The Multiplayer Services Building Blocks are designed for flexible and modular integration of session management into your Unity projects. The ScriptableObject acts as a central configuration hub for the core functionality of these Building Blocks.
SessionSettingsSessionSettings ScriptableObject
The ScriptableObject stores parameters and settings related to your sessions. Crucially, includes the string, which is the primary identifier used for managing different types of sessions within your game.
SessionSettingsSessionSettingsSessionTypeSession management via SessionType
The string drives session management within the Building Block. When you create, join, or browse for sessions, each uses the specified in the active to filter and interact with the appropriate session. This approach enables dynamic configuration without requiring code changes for each session type.
SessionTypeVisualElementSessionTypeSessionSettingsImplementation: C# scripts, visual elements, and data separation
The Building Blocks implementation is primarily done through C# scripts. A key architectural principle is the clear separation between the visual representation (UI) and the underlying data and logic.
The details of this architecture are as follows:
- (UI) scripts: These scripts, extending
VisualElementor its derivatives, are responsible for rendering the UI components that players interact with, handle user input, and display session-related information. These scripts always expose aVisualElementfor aUXMLAttributereference or aSessionSettingsstring value that's propagated to theSessionTypescript so that it can work on the expected session.ViewModel - scripts: These scripts manage the actual session data, interact with Unity Multiplayer Services, and handle the game logic related to session states via subscribing to session events tracked by the
ViewModeland theSessionObserverAPI.ISession
This separation ensures that UI changes can be made independently of the core session logic, promoting maintainability and scalability.
UXML file composition and binding
The user interfaces in the Building Blocks are built using Unity Extensible Markup Language (UXML) files, which are Unity's equivalent of HTML for UI Toolkit. To learn about UXML scripts, refer to Introduction to UXML.
The details of this UI are as follows:
- UXML composition:
- UXML files define the structure and hierarchy of the UI. These files reference various types and can include custom
VisualElementimplementations. These files specify visual properties like styles, layout, and content.VisualElement
- UXML files define the structure and hierarchy of the UI. These files reference various
- Setting up the :
SessionType- To simplify the setup of and
SessionSettingson the Building Block elements, the UXML files are setup with UIToolkit's DataSource bindings to propagate a specificSessionTypeand associatedSessionSettingsto all childSessionTypefrom the root element of the UXML.VisualElement
- To simplify the setup of
To learn more about runtime bindings in UIToolkit, refer to Get started with runtime binding.
Use Multiplayer Play Mode with your Building Blocks
You can use the Multiplayer Play Mode package to test your Multiplayer Building Blocks locally with multiple simulated players. With this package, you can run multiple instances of your game within the Unity Editor, simulating a multiplayer environment without needing to build and deploy to separate devices.