LAN mode
LAN mode runs the relay in-process inside your Unity build. Your game opens an HTTP+WebSocket port, serves the web-controller bundle directly to phones on the same Wi-Fi, and never talks to the public internet.
For when LAN mode is the right choice (in-person events, no internet, sub-5ms latency), see Cloud vs LAN mode.
Setup
- Set
Relay ModetoLanonPhoneControllerManager. - Pick a
Lan Port(default7777; any unused port > 1024 works). - Press Play. The first run shows a firewall prompt on Windows / macOS — allow it. Your Unity process is now listening on
http://<lan-ip>:<port>/and serving the web-controller bundle to any phone that scans the QR. - Phones must be on the same Wi-Fi as your computer. Scan the QR; the controller UI opens directly. No internet, no cloud, no cost.
The Inspector shows the same code + QR + player list as Cloud mode. Your game code is identical — OnPlayerJoin, OnInput, SendToPlayer, etc. all work the same.
Architecture
Phone browser (same Wi-Fi) Unity build ───────────────────────── ────────────────────── widget events ─────► ws://<lan-ip>:7777 (in-process server) │ ▼ SessionManager │ ▼ PhoneControllerManager │ ▼ Your game codeThere is no relay process. The Unity build is the relay. Phones reach it directly via your computer’s LAN IP.
Platform support
| Platform | Supported |
|---|---|
| Windows / macOS / Linux desktop | ✓ |
| Unity 6000.x WebGL | ✗ (browsers can’t host listening sockets) |
| iOS / Android host (mobile build acting as host) | Partial — the host can serve, but iOS prompts for Local Network permission |
| PS / Xbox / Switch | ✓ (treat as desktop) |
On WebGL, LocalLanTransport is tagged [Obsolete(error: true)] so any reference to the type fails at build time. PhoneControllerManager with RelayMode.Lan throws PlatformNotSupportedException at runtime if it slipped through. Use Cloud mode for WebGL builds.
Picking the LAN IP
LocalRelayServer.GetPrimaryLanIp() auto-picks an IP. On multi-NIC machines (VPN, virtualization, multiple Wi-Fi adapters), this can pick the wrong interface. The Inspector’s Lan IP Override field lets you set it manually — useful for laptops with a Hyper-V or Docker virtual interface.
// Or set it programmatically:manager.LanIpOverride = "192.168.1.42";Firewall
The first LAN-mode run on Windows or macOS triggers a firewall prompt asking whether to allow incoming connections. Allow. If you accidentally clicked Block, both OSes remember the denial — remove Unity from the firewall rules and retry.
Troubleshooting
For full coverage including AP isolation, multi-NIC pitfalls, and Android cleartext, see Troubleshooting → LAN mode.
The most common failure: AP isolation. Some Wi-Fi networks (corporate, guest, hotel) block client-to-client traffic. The phone loads the controller page over HTTP but the WebSocket fails. Switch to a home network or hotspot from your phone to verify. Can’t fix in code.
Why no “Hybrid” mode?
A combined session that auto-upgrades same-Wi-Fi phones to LAN while still serving remote players over Cloud is theoretically attractive. It’s not implemented because browsers block it — the Cloud session is HTTPS, and a same-Wi-Fi LAN connection would have to open ws:// to a private IP. That’s mixed content. Browsers refuse.
When Local Network Access ships broadly across iOS Safari, Android Chrome, and desktop browsers, Hybrid becomes worth building. Until then, pick the mode that fits your audience.
Next
- When LAN is the right choice: Cloud vs LAN mode.
- LAN-specific failures: Troubleshooting.