To use the Multiplayer Unity Building Blocks, set up the following in your project:
The Multiplayer Building Blocks are designed for flexible and modular integration of session management into your Unity projects. The SessionSettings ScriptableObject acts as a central configuration hub for the core functionality of these Building Blocks.
The SessionSettings ScriptableObject stores parameters and settings related to your sessions. Crucially, SessionSettings includes the SessionType string, which is the primary identifier used for managing different types of sessions within your game.
The SessionType string drives session management within the Building Block. When you create, join, or browse for sessions, each VisualElement uses the SessionType specified in the active SessionSettings to filter and interact with the appropriate session. This approach enables dynamic configuration without requiring code changes for each session type.
The Building Blocks implementation is primarily done through C# scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary. 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:
VisualElement (UI) scripts: These scripts, extending VisualElement or 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 a UXMLAttribute for a SessionSettings reference or a SessionType string value that’s propagated to the ViewModel script 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 SessionObserver and the ISession API.This separation ensures that UI changes can be made independently of the core session logic, promoting maintainability and scalability.
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:
VisualElement types and can include custom VisualElement implementations. These files specify visual properties like styles, layout, and content.SessionType:
SessionSettings and SessionType on the Building Block elements, the UXML files are setup with UIToolkit’s DataSource bindings to propagate a specific SessionSettings and associated SessionType to all child VisualElement from the root element of the UXML.To learn more about runtime bindings in UIToolkit, refer to Get started with runtime binding.
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.