Unity multiplayer, hosted
Install the package from the Package Manager by Git URL. Add com.unity.webrtc to connect players directly; without it, everything routes through the server relay and still works — useful on platforms where WebRTC is not available. Unity 2021.3 and newer are supported.
Because the API is not tied to Unity, a single game key serves every build you publish. A mobile player and a browser player can quickmatch into the same room.
A complete Unity integration
using MultiplayerApi;
using Newtonsoft.Json.Linq;
using UnityEngine;
public class Net : MonoBehaviour {
Multiplayer mp;
Room room;
async void Start() {
mp = new Multiplayer("mp_pk_...") { DisplayName = "Alice" };
await mp.Login();
room = await mp.Quickmatch(new JObject { ["mode"] = "ffa", ["max_players"] = 8 });
room.OnMembersChanged += members => Spawner.Sync(members);
room.OnPeerMessage += (bytes, from) => Ghosts.Apply(from, bytes);
}
void Update() {
if (room == null) return;
var p = transform.position;
room.Send(new { x = p.x, y = p.y, z = p.z });
}
}What goes where
| Channel | Call | Delivery | Use it for |
|---|---|---|---|
| Direct | room.send(data) | peer-to-peer, best effort, zero server cost | positions, aim, animation |
| State | room.set(path, value) | server-validated, kept for the match, reaches late joiners | health, score, whose turn |
| Events | room.emitEvent(topic, data) | ordered, guaranteed, not persisted | chat, rematch, one-shots |
- Throttle
Sendto 15–20 times per second in production; interpolate the rest. - Password recovery is built in: your server requests a token with the secret key, the client calls
await mp.ResetPassword(token, password). - Non-browser clients send no Origin header, so the
originsallow-list never blocks a Unity build.
Is this a replacement for Unity Netcode for GameObjects?
It replaces the hosting side: accounts, matchmaking, relay, signaling and validated state are hosted for you. You keep your gameplay code and sync what you choose over three simple channels.
Can Unity and web players play together?
Yes. One game key serves every build, so Unity, WebGL and browser clients join the same rooms.
Does it work without com.unity.webrtc?
Yes. Without it, the SDK routes all traffic through the server relay.
Make your game online today
Free sandbox keys in one call, no account and no card. $19.99/month when you ship, for every game you make.
Free sandbox · $19.99/mo to go live · cancel anytime