unity-networking
БесплатноБез исполняемых скриптовНе проверенUnity multiplayer networking with NGO, Mirror, Photon, and Fish-Net. PROACTIVELY activate for: (1) building Unity multiplayer games, (2) Netcode for…
от JosiahSiegel★ 67 звёзд на GitHubОб этом скилле
Unity Networking and Multiplayer
Overview
Reference for implementing multiplayer systems and backend services in Unity. Covers the major networking frameworks, authority models, common multiplayer patterns, and Unity Gaming Services integration.
Networking Framework Comparison
| Framework | Type | Best For | License |
|---|---|---|---|
| Netcode for GameObjects (NGO) | Client-hosted / Dedicated | Unity-native projects, UGS integration | Free (Unity) |
| Mirror | Client-hosted / Dedicated | Open-source alternative, mature ecosystem | MIT |
| Photon PUN 2 | Cloud-hosted | Quick prototyping, room-based games | Free tier + paid |
| Photon Fusion 2 | Cloud/Self-hosted | Competitive games, tick-based simulation | Free tier + paid |
| Fish-Net | Client-hosted / Dedicated | Performance-critical, Mirror alternative | MIT |
Netcode for GameObjects (NGO)
Setup
- Install via Package Manager:
com.unity.netcode.gameobjects - Add
NetworkManagerto a scene GameObject - Select transport (Unity Transport is default)
- Mark networked prefabs with
NetworkObjectcomponent - Register prefabs in NetworkManager's prefab list
Core Components
| Component | Purpose |
|---|---|
NetworkManager |
Manages connections, spawning, scene management |
NetworkObject |
Required on all networked GameObjects |
NetworkBehaviour |
Base class for networked scripts (replaces MonoBehaviour) |
NetworkVariable<T> |
Synchronized variable with ownership/permissions |
NetworkTransform |
Automatic position/rotation sync |
NetworkAnimator |
Automatic Animator parameter sync |
RPCs (Remote Procedure Calls)
public class PlayerCombat : NetworkBehaviour
{
NetworkVariable<int> _health = new(100,
NetworkVariableReadPermission.Everyone,
NetworkVariableWritePermission.Server);
[ServerRpc]
void AttackServerRpc(ulong targetId)
{
// Runs on server - validate and apply damage
if (!IsServer) return;
var target = NetworkManager.SpawnManager.SpawnedObjects[targetId];
target.GetComponent<PlayerCombat>().TakeDamage(10);
}
[ClientRpc]
void PlayHitEffectClientRpc(Vector3 position)
{
// Runs on all clients - visual feedback only
Instantiate(hitVFX, position, Quaternion.identity);
}
void TakeDamage(int amount)
{
_health.Value -= amount;
PlayHitEffectClientRpc(transform.position);
}
}
| RPC Type | Direction | Use For |
|---|---|---|
[ServerRpc] |
Client -> Server | Player actions, requests |
[ClientRpc] |
Server -> All Clients | VFX, sound, UI updates |
[ClientRpc(SendTo.Owner)] |
Server -> Owner Client | Owner-specific feedback |
NetworkVariable Permissions
// Server-writable (default) - authoritative state
NetworkVariable<int> score = new(0, writePerm: NetworkVariableWritePermission.Server);
// Owner-writable - client-authoritative (use sparingly)
NetworkVariable<Vector3> cursorPos = new(writePerm: NetworkVariableWritePermission.Owner);
Use OnValueChanged callback for UI reactions:
_health.OnValueChanged += (oldVal, newVal) => healthBar.value = newVal;
Authority Models
| Model | Description | When to Use |
|---|---|---|
| Server-Authoritative | Server validates all actions, clients are thin | Competitive, anti-cheat critical |
| Client-Authoritative | Clients own their state, server relays | Cooperative, trust-based |
| Client Prediction + Server Reconciliation | Client predicts locally, server corrects | FPS, fast-paced action |
| Relay / Listen Server | One player hosts, others connect via relay | Casual, small lobbies |
Server-Authoritative Flow
Client: Press "Attack" -> Send ServerRpc(targetId)
Server: Validate range/cooldown -> Apply damage -> Update NetworkVariable
Server: Send ClientRpc for VFX
All Clients: Play hit effect
Never trust client data. Validate positions, cooldowns, ammunition, and line-of-sight on the server.
Common Multiplayer Patterns
Lobby System
1. Player authenticates (UGS Auth / custom)
2. Player creates or joins lobby (UGS Lobby / custom)
3. Lobby fills -> host starts game
4. Relay allocation for NAT traversal (UGS Relay)
5. All players connect to relay
6. NetworkManager starts host/client
Spawn and Despawn
// Server-side spawning
var instance = Instantiate(prefab, spawnPoint, Quaternion.identity);
instance.GetComponent<NetworkObject>().SpawnWithOwnership(clientId);
// Server-side despawning
networkObject.Despawn(); // Removes from all clients
Scene Management
Use NetworkManager.SceneManager.LoadScene("GameScene", LoadSceneMode.Single) for synchronized scene loading. Only the server/host should call this.
REST API and WebSocket Integration
REST API (UnityWebRequest)
async Awaitable<T> GetAsync<T>(string url)
{
us
Установить unity-networking в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл unity-networking?
Unity multiplayer networking with NGO, Mirror, Photon, and Fish-Net. PROACTIVELY activate for: (1) building Unity multiplayer games, (2) Netcode for GameObjects (NGO) setup and patterns, (3) Mirror networking, (4) Photon PUN and Photon Fusion, (5) Fish-Net networking, (6) RPCs (ClientRpc, ServerRpc), (7) NetworkVariable and network synchronization, (8) lobby and matchmaking systems, (9) dedicated server hosting and Relay, (10) server-authoritative architecture, (11) lag compensation and prediction. Provides: networking-stack comparison, NGO templates, RPC patterns, NetworkVariable usage, lobby/matchmaking setup, and authoritative-server design.
Как установить скилл unity-networking?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл unity-networking запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic