Skip to content

Connect Mirror

Use the Mirror transport to create an ephemeral room and connect remote clients. The host shares the room code after the relay registers the room.

Before you start, you need the following:

The transport uses UDP and does not support WebGL builds.

  1. Install the transport.

    In Unity, open the Window menu. Under Package Management, select Package Manager. In the Package Manager window, open the Add menu and select Install package from git URL. Enter the following URL in the box:

    https://github.com/abdelfattahradwan/blitz-relay-for-mirror.git

    Click Install.

  2. Assign the transport.

    On the GameObject that contains Mirror’s NetworkManager, complete the following setup:

    • Add BlitzRelayTransport and assign it to Transport on the manager.
    • Set Relay Address, Relay Port, and Relay Key to match the running relay.
    • On the host instance, leave Room Code empty.
    • Keep the manager’s Network Address box non-empty, for example localhost. Mirror requires a value before starting a client, but this transport uses Relay Address for the actual connection.

    Set NetworkManager.maxConnections separately from the transport’s client limit. Mirror’s local host client does not use a relay client slot.

  3. Start a host and publish the room code.

    Attach the following component to an object that remains active while connecting. In the Inspector, assign the manager and transport. Configure the relay settings before calling StartHost():

    using System.Collections;
    using BlitzRelay.Mirror;
    using Mirror;
    using UnityEngine;
    public sealed class RelaySession : MonoBehaviour
    {
    [SerializeField] private NetworkManager networkManager;
    [SerializeField] private BlitzRelayTransport transport;
    private void OnEnable()
    {
    transport.OnTransportFailure += HandleRelayFailure;
    }
    private void OnDisable()
    {
    transport.OnTransportFailure -= HandleRelayFailure;
    }
    public void StartHost()
    {
    networkManager.StartHost();
    StartCoroutine(PublishRoomCode());
    }
    private IEnumerator PublishRoomCode()
    {
    while (transport.ServerSocket.SocketState == RelaySocketState.Starting)
    {
    yield return null;
    }
    if (transport.ServerSocket.SocketState == RelaySocketState.Started)
    {
    Debug.Log($"Room code: {transport.GetRoomCode()}");
    }
    }
    private void HandleRelayFailure(string reason)
    {
    Debug.LogError(reason);
    networkManager.StopHost();
    }
    public void Join(string roomCode)
    {
    transport.SetRoomCode(roomCode);
    networkManager.StartClient();
    }
    }

    The component logs the room code after registration completes. Replace the log with your invitation UI. To run a dedicated game server instead, call NetworkManager.StartServer() and handle relay failures by stopping the server.

  4. Join from another game instance.

    Use the same relay address, UDP port, and key. Call Join(roomCode) with the host’s code. Use Mirror’s connection and authentication callbacks to confirm that the game session is ready.

NetworkServer.active and the transport’s ServerActive() can be true before relay registration finishes. Wait for ServerSocket.SocketState == RelaySocketState.Started before publishing the code.

Next, test a session. For payload limits and runtime methods, see the Mirror transport reference. To use persistent rooms, configure Mirror host migration before players join.