Files
nexus/wiki/concepts/UnityRelay.md
2026-04-26 12:02:53 +08:00

1.4 KiB
Raw Blame History

title, type, tags, sources, last_updated
title type tags sources last_updated
Unity Relay concept
networking
unity
ugs
nat-traversal
unity-multiplayer-engineer
2026-04-26

Aliases

  • Unity Gaming Services Relay
  • UGS Relay

Definition

Unity Relay 是 Unity Gaming ServicesUGS提供的流量中继服务,用于解决 NAT 穿透问题,使不同网络环境下的玩家能够建立连接。玩家托管游戏必须使用 Relay直接 P2P 连接会暴露主机 IP 地址。

Key Features

  • 无需专用服务器:玩家之一作为 Host其他玩家通过 Relay 连接
  • IP 保护Relay 隐藏了 Host 的真实 IP 地址
  • 多平台兼容:支持 UDP/TCP DTLS 加密传输

Workflow

  1. Host 初始化 Unity Services + 匿名认证
  2. Host 创建 Relay Allocation获取 Join Code
  3. Host 将 Join Code 分享给其他玩家
  4. Clients 通过 Join Code 加入 Relay
  5. UnityTransport 自动将流量路由至 Relay 服务器

Security Note

"Always use Relay for player-hosted games — direct P2P exposes host IP addresses"