ODIN Mirror Transport
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, 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
- Install Mirror into your project using the package manager. Mirror is available from the Unity Asset Store.
- Download the latest ODIN Unity SDK .unitypackage from the Github Releases page and import it into your project.
- Download the latest ODIN Transport for Unity SDK .unitypackage from the Github Releases page and import it into your project.
- Locate the
OdinManager_NetworkingVariant
prefab in the "Packages/4Players ODIN Transport for Mirror Networking/Prefabs" directory and drop it into your scene. - Select the
OdinManager
GameObject, click on theManage Access
button underClient Authentication
, and generate an Access Key. For more information on Access Keys, take a look at our Understanding Access Keys chapter. - Attach a
NetworkManager
component to a GameObject in your Scene. - Attach an
Odin Transport
component to the same GameObject as theNetworkManager
. - Drag the
Odin Transport
component into theTransport
slot on theNetworkManager
.
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:
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:
- Attach the
OdinPositionalAudio
script to the Player-Prefab's GameObject that has theNetworkIdentity
component. - Specify your desired proximity room name in the script.
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:
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 set up 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:
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 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.