In this lesson, you will learn how to bridge your local Unity project with the cloud dashboard to enable seamless backend connectivity for your multiplayer game.
Linking the Project to the Cloud
Before you can utilize services like Unity Gaming Services (UGS)—which powers features like Relay, Lobby, and Authentication—you must establish a "handshake" between your local Editor and the Unity Cloud.
Navigate to Edit > Project Settings > Services. Here, you will link your project to an existing Unity Cloud Organization and Project ID. This mapping is vital because it assigns a unique identifier to your game, ensuring that all telemetry, player data, and network traffic are routed to your specific cloud environment. Once linked, the project-id is stored in your project settings, acting as the key that unlocks access to the UGS backend infrastructure.
Initializing the SDK
Once your project is linked, you must initialize the services at runtime. While most UGS packages handle this automatically, it is best practice to ensure UnityServices.InitializeAsync() is called before you attempt to access network-specific features.
Consider this snippet placed within your network bootstrapper script:
using Unity.Services.Core;
using UnityEngine;
public class NetworkInitializer : MonoBehaviour
{
async void Awake()
{
try
{
await UnityServices.InitializeAsync();
Debug.Log("UGS initialized successfully.");
}
catch (System.Exception e)
{
Debug.LogError($"Initialization failed: {e.Message}");
}
}
}
By calling this in your Awake method, you ensure that the SDK fetches your environment configuration and establishes a secure connection to the Unity backend. Without this initialization, your NetworkManager will fail to register with the cloud relay services, preventing clients from finding or joining your game sessions.
Think of the linking process as signing a lease for a digital space, and InitializeAsync() as turning the key in the front door. Both are mandatory prerequisites to move from a standalone networked prototype to a live, cloud-connected multiplayer service.
Key Takeaway: Linking your project to the Unity Dashboard creates the identity for your game in the cloud, while InitializeAsync() validates that identity and activates the necessary backend services for runtime communication.