Developer Documentation

ODIN Transport for Mirror Networking

This guide shows how to use the ODIN Transport for Mirror Networking package to provide P2P networking in your Unity games. The ODIN Transport package includes a Transport implementation, allowing Mirror to send and receive data over the 4Players ODIN servers.

ODIN Transport is designed to work in combination with the ODIN Voice Chat service, but can be used without utilizing voice.

What is Mirror?

“Mirror is a system for building multiplayer capabilities for Unity games. It is built on top of the lower level transport real-time communication layer, and handles many of the common tasks that are required for multiplayer games.” Mirror Docs

Mirror takes care of essentials like synchronizing player positions, animations, health and other game variables. It instantiates and destroys game objects across the network and ensures that these objects are managed correctly across the connected clients. It also handles player connections and disconnects and networked scenes.

While Mirror addresses these aspects of networking, it does not handle the actual transmission of data. This is where a transport layer, like the ODIN Transport for Mirror Networking, comes into play.

ODIN’s Role:

  • Data Transmission: While Mirror organizes and prepares the data for transmission, ODIN is responsible for actually sending and receiving this data over the 4Players ODIN servers.

  • Scalability and Reliability: By leveraging 4Players servers, ODIN Transport ensures that your multiplayer games can handle a larger number of concurrent players and provide a stable connection.

  • Voice Chat Integration: When used in combination with ODIN Voice Chat, ODIN Transport seamlessly integrates all kinds of voice communication into your multiplayer games.

In essence, while Mirror lays the groundwork for creating a multiplayer game within Unity, ODIN Transport bridges the gap between the game’s logic and the actual data transmission.

Setup

  1. Install Mirror into your project using the package manager. Mirror is available from the Unity Asset Store.
  2. Download the latest ODIN Unity SDK .unitypackage from the Github Releases page and import it into your project.
  3. Download the latest ODIN Transport for Unity SDK .unitypackage from the Github Releases page and import it into your project
  4. Locate the OdinManager_NetworkingVariant prefab in the “Packages/4Players ODIN Transport for Mirror Networking/Prefabs” directory and drop it into your scene.
  5. Select the OdinManager GameObject, click on the Manage Access button under Client Authentication and generate an Access Key. For more information on Access Keys, take a look at our Understanding Access Keys chapter.
  6. Attach a NetworkManager component to a GameObject in your Scene.
  7. Attach a Odin Transport component to the same GameObject as the NetworkManager
  8. Drag the Odin Transport component into the Transport slot on the NetworkManager
The Mirror Network Manager setup with Odin Transport.

The Mirror Network Manager setup with Odin Transport.

For a more in-depth setup guide for ODIN, take a look at our Getting Started with Unity chapter or dive into our Unity video tutorial series.

Connecting

ODIN Transport uses ODIN rooms to handle networking messages. This means instead of entering an IP Address to start or host a client, you provide a room name to the networkAddress field of the NetworkManager. Here’s how you can do it:

Simple Mirror Connection script
public class MinimalMirrorConnection : MonoBehaviour
{
    [SerializeField] private string roomId = "default";
    
    public void StartHost()
    {
        NetworkManager.singleton.networkAddress = roomId;
        NetworkManager.singleton.StartHost();
    }

    public void Connect()
    {
        NetworkManager.singleton.networkAddress = roomId;
        NetworkManager.singleton.StartClient();
    }
}

Note: When going live with your game, ensure you use unique room names. Failing to do so will result in all players connecting to the same networking room.

Using the Positional Audio script

For proximity voice chat functionality in your game, it’s essential to link the incoming voice stream with the corresponding player’s avatar. The ODIN Transport for Mirror package offers a handy utility script called OdinPositionalAudio to streamline this process.

Here’s how to use it:

  1. Attach the OdinPositionalAudio script to the Player-Prefab’s GameObject that has the NetworkIdentity component.
  2. Specify your desired proximity room name in the script.
  3. (optional)

Once these steps are completed, the OdinPositionalAudio script will take care of the rest. When a player connects, the script automatically generates a combined room name using the given proximity room’s name and the networking room’s name. The combination looks like this:

Get proximity room name
public string GetFullPositionalRoomName()
        {
            return $"{positionalRoomName}-{GetNetworkingRoomName()}";
        }

If you’re new to setting up your Player Prefab for multiplayer in Mirror, consult the Mirror Getting Started Guide for a comprehensive walkthrough.

What’s next?

We’ve shown you how to setup Mirror Networking to use ODIN as a Relay Transport. For even more information on Unity with Odin Voice Chat, check out our Discord and take a look at the following guides we’ve prepared for you:

Join us on Discord

Getting started with ODIN

Follow this guide to install ODIN in an empty Unity project. We’ll try out one of the samples that come with ODIN and explain how it works and which steps are required to implement ODIN into your own game.

ODIN and Mirror Networking

ODIN is best suited to be added to a multiplayer game. In this guide, we’ll create a basic multiplayer with 3D positional audio based on Mirror Networking. You’ll also learn how to leverage ODIN APIs like user data.