unity-netcode
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBefore calling any skill in this module: if you are about to call a skill with parameters guessed from its name or description, STOP — read this file (or fetch its schema via) first. If you already have the parameter definitions from recommend/schema, you may proceed straight to dryRun.GET /skills/recommend?includeSchema=true
**调用本模块中的任何技能之前:**如果您打算根据技能名称或描述猜测参数来调用技能,请停止——先阅读本文档(或通过获取其schema)。如果您已经从推荐/schema中获得了参数定义,可以直接进行dryRun。GET /skills/recommend?includeSchema=true
Triggers
触发场景
- Scaffolding multiplayer
- Registering network prefabs
- Wiring spawn logic
- Starting host/server/client
- 搭建多人联机、注册网络预制体、连接生成逻辑、启动 host/server/client
- 搭建多人联机系统
- 注册网络预制体
- 配置生成逻辑
- 启动host/server/client
- 搭建多人联机、注册网络预制体、连接生成逻辑、启动 host/server/client
Unity Netcode for GameObjects Skills
Unity Netcode for GameObjects 技能集
Automation for Netcode for GameObjects (NGO) multiplayer setup and operations. Every skill is source-verified against NGO 2.x; when the package is absent, each skill returns a error with install instructions. A subset of skills additionally require NGO 2.5.0+ (see NGO 2.5+ features) — on an older 2.x install they return a structured "requires 2.5.0+" error instead of a compile error, since AttachableBehaviour/AttachableNode/ComponentController are detected by reflection, not by a dedicated version symbol.
NoNetcode()Requires:(2.x), Unity 6000.0+. Strongly recommended: before calling anycom.unity.netcode.gameobjectsskill, load netcode-design. NGO lifecycle and permission rules are strict; skills alone cannot prevent incorrect business code.netcode_*
Netcode for GameObjects(NGO)多人联机系统搭建与操作的自动化工具。每个技能均针对NGO 2.x进行了源码验证;当缺少该包时,每个技能都会返回错误并附带安装说明。部分技能还需要NGO **2.5.0+**版本(参见NGO 2.5+功能)——在旧版2.x安装环境中,它们会返回结构化的“需要2.5.0+版本”错误,而非编译错误,因为AttachableBehaviour/AttachableNode/ComponentController是通过反射检测的,而非专用版本符号。
NoNetcode()依赖要求:(2.x),Unity 6000.0+。 强烈建议:在调用任何com.unity.netcode.gameobjects技能之前,加载netcode-design。NGO的生命周期和权限规则非常严格;仅靠技能无法避免错误的业务代码。netcode_*
Guardrails
防护规则
Operating Mode (v1.9 three-tier):
-
Approval (default): query/list/info skills (,
netcode_check_setup,netcode_get_manager_info,netcode_get_transport_info,netcode_list_network_objects,netcode_get_network_object_info,netcode_list_network_prefabs,netcode_list_network_behaviours,netcode_get_spawn_manager_info,netcode_get_scene_manager_info,netcode_get_status,netcode_version) run directly. Mutators (create/configure/attach/add) are FullAuto — onnetcode_attachable_info, run the grant protocol.MODE_RESTRICTED -
Auto / Bypass: SemiAuto and FullAuto run directly.
-
Auto-forbidden in this module:
- →
SkillOperation.Delete,netcode_remove_manager,netcode_remove_network_objectnetcode_remove_from_prefabs_list - →
MayTriggerReload = true(writes a newnetcode_add_network_behaviour_script, forces script compile + Domain Reload).cs - →
MayEnterPlayMode = true,netcode_start_host,netcode_start_server,netcode_start_clientnetcode_shutdown
These are reachable only under Bypass mode or via a user-managed Allowlist entry; the grant flow returns. Runtime control + Behaviour-script generation are the practical reason this module is gated.MODE_FORBIDDEN -
Whenis missing, every skill returns a
com.unity.netcode.gameobjectserror with install instructions.NoNetcode()
DO NOT (common hallucinations):
- /
netcode_spawn_object— do not exist. Spawn must happen in runtime code (NetworkBehaviour) vianetcode_spawn_playeror.Spawn(). Skills do not proxy Spawn because Spawn requires a running NetworkManager.NetworkManager.SpawnManager.InstantiateAndSpawn - — does not exist. Scene registration goes through Build Settings +
netcode_register_scene. This module only exposesEnableSceneManagementfor reading/writing the config.netcode_configure_scene_management - /
netcode_set_tick_rateas standalone skills — do not exist. Usenetcode_set_protocolfor all NetworkConfig edits.netcode_configure_manager - Do not assume works in Edit Mode. All Runtime control skills require PlayMode.
netcode_start_host - Do not assume automatically attaches a
netcode_add_to_prefabs_listcomponent. CallNetworkObjectfirst.netcode_add_network_object
Routing:
- Plain GameObject hierarchy creation →
gameobject - Attach NetworkObject / NetworkTransform / other networking components → this module
- Generic player-prefab components (Rigidbody / Collider / Animator) →
component - Runtime scene switching (LoadScene) → call from the generated NetworkBehaviour; this module does not execute it
NetworkManager.SceneManager.LoadScene - Code-level design decisions (RPC direction, NetworkVariable permission) → netcode-design advisory
操作模式(v1.9 三级模式):
-
审批模式(默认):查询/列表/信息类技能(、
netcode_check_setup、netcode_get_manager_info、netcode_get_transport_info、netcode_list_network_objects、netcode_get_network_object_info、netcode_list_network_prefabs、netcode_list_network_behaviours、netcode_get_spawn_manager_info、netcode_get_scene_manager_info、netcode_get_status、netcode_version)可直接运行。修改类技能(创建/配置/附加/添加)为全自动模式——在netcode_attachable_info模式下,需运行授权流程。MODE_RESTRICTED -
自动模式 / 绕过模式:半自动和全自动技能可直接运行。
-
本模块中自动禁用的操作:
- →
SkillOperation.Delete、netcode_remove_manager、netcode_remove_network_objectnetcode_remove_from_prefabs_list - →
MayTriggerReload = true(写入新的netcode_add_network_behaviour_script文件,强制脚本编译 + 域重载).cs - →
MayEnterPlayMode = true、netcode_start_host、netcode_start_server、netcode_start_clientnetcode_shutdown
这些操作仅在绕过模式下或通过用户管理的白名单条目才能执行;授权流程会返回错误。运行时控制和行为脚本生成是本模块被限制的实际原因。MODE_FORBIDDEN -
当缺少包时,所有技能都会返回
com.unity.netcode.gameobjects错误并附带安装说明。NoNetcode()
切勿(常见错误用法):
- /
netcode_spawn_object——不存在这些技能。生成操作必须在运行时代码(NetworkBehaviour)中通过netcode_spawn_player或.Spawn()执行。技能不会代理生成操作,因为生成需要运行中的NetworkManager。NetworkManager.SpawnManager.InstantiateAndSpawn - ——不存在该技能。场景注册需通过Build Settings +
netcode_register_scene完成。本模块仅提供EnableSceneManagement用于读写配置。netcode_configure_scene_management - /
netcode_set_tick_rate作为独立技能——不存在这些技能。所有NetworkConfig编辑请使用netcode_set_protocol。netcode_configure_manager - 不要假设在编辑模式下可用。所有运行时控制技能都需要进入PlayMode。
netcode_start_host - 不要假设会自动附加
netcode_add_to_prefabs_list组件。请先调用NetworkObject。netcode_add_network_object
路由指引:
- 普通GameObject层级创建 → 使用模块
gameobject - 附加NetworkObject / NetworkTransform / 其他网络组件 → 使用本模块
- 通用玩家预制体组件(Rigidbody / Collider / Animator) → 使用模块
component - 运行时场景切换(LoadScene) → 从生成的NetworkBehaviour中调用;本模块不执行此操作
NetworkManager.SceneManager.LoadScene - 代码层面的设计决策(RPC方向、NetworkVariable权限) → 参考netcode-design的建议
Object Targeting
对象定位
netcode_add_*netcode_configure_*- — scene object name
name - — Unity InstanceID (exact)
instanceId - — hierarchy path
pathParent/Child
Prefer when there is a chance of duplicate names.
instanceIdnetcode_add_*netcode_configure_*- —— 场景对象名称
name - —— Unity实例ID(精确匹配)
instanceId - —— 层级路径
pathParent/Child
当存在名称重复的可能时,优先使用。
instanceIdSkills
技能列表
Setup & Validation
搭建与验证
| Skill | Purpose | Key Parameters |
|---|---|---|
| Verify package, NetworkManager, Transport, PlayerPrefab, and PrefabsList consistency | |
| Create NetworkManager + UnityTransport | |
| Bulk-edit NetworkConfig (TickRate, ConnectionApproval, EnableSceneManagement, NetworkTopology, ...) | |
| Read NetworkConfig + runtime state | |
| Delete the NetworkManager (must already be Shutdown) | |
| 技能 | 用途 | 关键参数 |
|---|---|---|
| 验证包、NetworkManager、传输层、玩家预制体和预制体列表的一致性 | |
| 创建NetworkManager + UnityTransport | |
| 批量编辑NetworkConfig(TickRate、连接审批、场景管理启用、网络拓扑等) | |
| 读取NetworkConfig + 运行时状态 | |
| 删除NetworkManager(必须已关闭) | |
Transport
传输层
| Skill | Purpose | Key Parameters |
|---|---|---|
| Direct connection: set Address / Port / ServerListenAddress | |
| Relay mode (mutually exclusive with direct connection) | |
| Simulate latency / jitter / packet loss (development only) | |
| Read current transport info | |
| 技能 | 用途 | 关键参数 |
|---|---|---|
| 直接连接:设置地址/端口/服务器监听地址 | |
| 中继模式(与直接连接互斥) | |
| 模拟延迟/抖动/丢包(仅用于开发) | |
| 读取当前传输层信息 | |
NetworkObject
NetworkObject
| Skill | Purpose | Key Parameters |
|---|---|---|
| Attach NetworkObject to a GameObject | |
| Modify fields on an existing NetworkObject | same as above |
| Remove a NetworkObject (must not be currently spawned) | same as above |
| List all NetworkObjects in scene (including runtime state) | |
| Query a single NetworkObject in detail | same as above |
| 技能 | 用途 | 关键参数 |
|---|---|---|
| 为GameObject附加NetworkObject组件 | |
| 修改现有NetworkObject的字段 | 同上 |
| 移除NetworkObject(当前未生成) | 同上 |
| 列出场景中所有NetworkObject(包括运行时状态) | |
| 详细查询单个NetworkObject | 同上 |
NetworkPrefabsList
网络预制体列表
| Skill | Purpose | Key Parameters |
|---|---|---|
| Create a NetworkPrefabsList asset | |
| Add a prefab (optional override: None/Prefab/Hash) | |
| Remove a prefab entry | |
| List every entry with its hash | |
| Set | |
| 技能 | 用途 | 关键参数 |
|---|---|---|
| 创建NetworkPrefabsList资源 | |
| 添加预制体(可选覆盖模式:None/Prefab/Hash) | |
| 移除预制体条目 | |
| 列出所有条目及其哈希值 | |
| 设置 | |
Components
组件
| Skill | Purpose | Key Parameters |
|---|---|---|
| Attach NetworkTransform with axis sync toggles | target + 15 optional fields |
| Edit fields / thresholds on an existing NT | includes PositionThreshold etc. |
| Attach NetworkRigidbody / NetworkRigidbody2D | |
| Attach NetworkAnimator (Animator required) | target |
| Generate a NetworkBehaviour script template (OnNetworkSpawn/Despawn + optional RPC/NetworkVariable/Ownership/NGO 2.5+ OnNetworkPreDespawn) | |
| List NetworkBehaviour subclass instances in the scene | |
| 技能 | 用途 | 关键参数 |
|---|---|---|
| 附加带轴同步开关的NetworkTransform | 目标对象 + 15+可选字段 |
| 编辑现有NT的字段/阈值 | 包含PositionThreshold等 |
| 附加NetworkRigidbody / NetworkRigidbody2D | |
| 附加NetworkAnimator(需要Animator组件) | 目标对象 |
| 生成NetworkBehaviour脚本模板(包含OnNetworkSpawn/Despawn + 可选RPC/NetworkVariable/所有权/NGO 2.5+ OnNetworkPreDespawn) | |
| 列出场景中NetworkBehaviour子类实例 | |
Scene & Spawning Query
场景与生成查询
| Skill | Purpose |
|---|---|
| Set EnableSceneManagement / LoadSceneTimeOut / ClientSynchronizationMode |
| Runtime: list SpawnedObjects |
| Runtime: read scene load state |
| 技能 | 用途 |
|---|---|
| 设置场景管理启用状态/场景加载超时/客户端同步模式 |
| 运行时:列出已生成对象 |
| 运行时:读取场景加载状态 |
Runtime Control (PlayMode required)
运行时控制(需进入PlayMode)
| Skill | Purpose |
|---|---|
| Start Host |
| Start Server |
| Start Client |
| Shut down (optional |
| Read IsHost / IsServer / IsClient, LocalClientId, ConnectedClients, NetworkTime |
| 技能 | 用途 |
|---|---|
| 启动主机 |
| 启动服务器 |
| 启动客户端 |
| 关闭(可选 |
| 读取IsHost/IsServer/IsClient、LocalClientId、已连接客户端、网络时间 |
NGO 2.5+ Features {#ngo-25-features}
NGO 2.5+功能 {#ngo-25-features}
Added in Netcode for GameObjects 2.5.0 (verified against the package CHANGELOG, PR #3518): / are an alternate "attach" parenting system that avoids the classic parenting pitfalls; network-synchronizes the enabled/disabled state of a list of components. On NGO 2.0–2.4.x ( is still active, but these types don't exist yet) every skill below returns a structured error instead of failing — call first to confirm.
AttachableBehaviourAttachableNodeNetworkObjectComponentControllerNETCODE_GAMEOBJECTSrequires 2.5.0+netcode_version| Skill | Purpose | Key Parameters |
|---|---|---|
| Report installed NGO version and 2.5+ feature availability | — |
| Audit the scene's AttachableBehaviour / AttachableNode / ComponentController distribution | |
| Attach an | target + |
| Attach an | target + |
| Attach a | target + |
| Set | target, |
Notes:
- must live on a child GameObject nested under a
AttachableBehaviour's hierarchy, not directly on theNetworkObject's own GameObject.NetworkObject - must belong to a different
AttachableNodethan theNetworkObjectinstances attaching to it.AttachableBehaviour - /
Attach()are runtime-only calls (require both instances spawned) and are intentionally not exposed as skills — same rationale asDetach()not existing (see DO NOT above): the caller must already have a running NetworkManager and do this from NetworkBehaviour code.netcode_spawn_object - 's
netcode_component_controller_configureaccepts whole GameObjects; NGO's owntargetPaths(invoked by this skill) expands each into every eligible child component with a publicOnValidate()property, skippingbool enabled/NetworkBehaviour/NetworkObject— identical to what happens when you drag a GameObject onto the Components field in the Inspector.NetworkManager
Netcode for GameObjects 2.5.0版本新增功能(已对照包CHANGELOG、PR #3518验证): / 是一种替代的“附加”父级系统,可避免传统父级的缺陷;可网络同步组件列表的启用/禁用状态。在NGO 2.0–2.4.x版本中(仍可用,但这些类型尚未存在),以下每个技能都会返回结构化的“需要2.5.0+版本”错误而非失败——请先调用确认版本。
AttachableBehaviourAttachableNodeNetworkObjectComponentControllerNETCODE_GAMEOBJECTSnetcode_version| 技能 | 用途 | 关键参数 |
|---|---|---|
| 报告已安装的NGO版本和2.5+功能可用性 | — |
| 审计场景中AttachableBehaviour / AttachableNode / ComponentController的分布情况 | |
| 为NetworkObject层级下的嵌套GameObject附加 | 目标对象 + |
| 附加 | 目标对象 + |
| 为GameObject附加 | 目标对象 + |
| 设置 | 目标对象, |
注意事项:
- 必须位于NetworkObject层级下的子GameObject上,不能直接位于NetworkObject自身的GameObject上。
AttachableBehaviour - 必须属于与附加到它的
AttachableNode实例不同的AttachableBehaviour。NetworkObject - /
Attach()是仅运行时调用(需要两个实例都已生成),并且故意不作为技能暴露——与Detach()不存在的理由相同(参见上文“切勿”部分):调用者必须已拥有运行中的NetworkManager,并从NetworkBehaviour代码中执行此操作。netcode_spawn_object - 的
netcode_component_controller_configure接受整个GameObject;NGO自身的targetPaths(由本技能调用)会将每个GameObject展开为所有符合条件的子组件(带有公共OnValidate()属性),跳过bool enabled/NetworkBehaviour/NetworkObject——与在Inspector中拖动GameObject到Components字段的操作完全一致。NetworkManager
Quick Start
快速开始
python
import unity_skills as upython
import unity_skills as u1. Inspect current state
1. 检查当前状态
u.call_skill("netcode_check_setup")
u.call_skill("netcode_check_setup")
2. Create NetworkManager + UnityTransport
2. 创建NetworkManager + UnityTransport
u.call_skill("netcode_create_manager", name="NetworkManager")
u.call_skill("netcode_create_manager", name="NetworkManager")
3. Configure the NetworkConfig
3. 配置NetworkConfig
u.call_skill("netcode_configure_manager",
tickRate=30,
connectionApproval=False,
enableSceneManagement=True,
networkTopology="ClientServer")
u.call_skill("netcode_configure_manager",
tickRate=30,
connectionApproval=False,
enableSceneManagement=True,
networkTopology="ClientServer")
4. Transport
4. 配置传输层
u.call_skill("netcode_set_transport_address",
address="127.0.0.1", port=7777, serverListenAddress="0.0.0.0")
u.call_skill("netcode_set_transport_address",
address="127.0.0.1", port=7777, serverListenAddress="0.0.0.0")
5. Player prefab setup
5. 玩家预制体设置
NOTE: add_network_object on a prefab path depends on GameObjectFinder support.
注意:在预制体路径上调用add_network_object依赖GameObjectFinder支持。
Safer route: instantiate the prefab in the scene first, then attach.
更安全的方式:先将预制体实例化到场景中,再附加组件。
u.call_skill("netcode_add_network_object", path="Assets/Prefabs/Player.prefab")
u.call_skill("netcode_create_prefabs_list", path="Assets/NetworkPrefabs.asset")
u.call_skill("netcode_add_to_prefabs_list",
listPath="Assets/NetworkPrefabs.asset",
prefabPath="Assets/Prefabs/Player.prefab")
u.call_skill("netcode_set_player_prefab", prefabPath="Assets/Prefabs/Player.prefab")
u.call_skill("netcode_add_network_object", path="Assets/Prefabs/Player.prefab")
u.call_skill("netcode_create_prefabs_list", path="Assets/NetworkPrefabs.asset")
u.call_skill("netcode_add_to_prefabs_list",
listPath="Assets/NetworkPrefabs.asset",
prefabPath="Assets/Prefabs/Player.prefab")
u.call_skill("netcode_set_player_prefab", prefabPath="Assets/Prefabs/Player.prefab")
6. Generate a NetworkBehaviour template
6. 生成NetworkBehaviour模板
u.call_skill("netcode_add_network_behaviour_script",
className="PlayerController",
path="Assets/Scripts/PlayerController.cs",
includeRpc=True, includeNetworkVariable=True)
u.call_skill("netcode_add_network_behaviour_script",
className="PlayerController",
path="Assets/Scripts/PlayerController.cs",
includeRpc=True, includeNetworkVariable=True)
7. Drive the session in PlayMode
7. 在PlayMode中驱动会话
u.call_skill("editor_play") # enter PlayMode
u.call_skill("netcode_start_host")
u.call_skill("netcode_get_status")
u.call_skill("netcode_shutdown")
u.call_skill("editor_stop")
undefinedu.call_skill("editor_play") # 进入PlayMode
u.call_skill("netcode_start_host")
u.call_skill("netcode_get_status")
u.call_skill("netcode_shutdown")
u.call_skill("editor_stop")
undefinedCritical Rules (must read)
关键规则(必须阅读)
- Spawn/Despawn are not exposed as skills. They must be called from NetworkBehaviour runtime code (Server authority). Skills handle prefab registration and NetworkManager lifecycle only.
- PlayerPrefab must be in a NetworkPrefabsList (enforced at runtime on 2.x). Register it with .
netcode_add_to_prefabs_list - Runtime control skills (start_*/shutdown) require PlayMode. Calls from Edit Mode return an error.
- Address vs ServerListenAddress have different meaning. On a client, is the target server IP. On a server,
Addressis the bind address (usuallyServerListenAddress).0.0.0.0 - switches between NetworkRigidbody and NetworkRigidbody2D. Unrelated physics settings (e.g.
useRigidbody2D) live elsewhere.Physics2D.AutoSyncTransforms
- 生成/销毁操作未作为技能暴露。它们必须从NetworkBehaviour运行时代码中调用(服务器权限)。技能仅处理预制体注册和NetworkManager生命周期。
- 玩家预制体必须在网络预制体列表中(2.x版本运行时强制要求)。使用注册。
netcode_add_to_prefabs_list - 运行时控制技能(start_*/shutdown)需要PlayMode。在编辑模式下调用会返回错误。
- Address与ServerListenAddress含义不同。在客户端,是目标服务器IP。在服务器,
Address是绑定地址(通常为ServerListenAddress)。0.0.0.0 - ****用于切换NetworkRigidbody和NetworkRigidbody2D。无关的物理设置(如
useRigidbody2D)在其他地方配置。Physics2D.AutoSyncTransforms
Version Scope
版本范围
Targets NGO 2.x (validated against 2.13.1). Legacy 1.x (old prefabs list layout, different RPC model) is out of scope for this module. The NGO 2.5+ features skills additionally require 2.5.0+ within that range; call to check before relying on them.
netcode_version针对NGO 2.x版本(已针对2.13.1验证)。旧版1.x(旧预制体列表布局、不同RPC模型)不在本模块的范围内。NGO 2.5+功能中的技能还需要该范围内的2.5.0+版本;在依赖这些技能之前,请调用检查版本。
netcode_versionExact Signatures
精确签名
For exact parameter names, defaults, and return fields, query or . This document is a routing and best-practice guide, not the authoritative signature source.
GET /skills/schemaunity_skills.get_skill_schema()如需精确的参数名称、默认值和返回字段,请查询或。本文档是路由和最佳实践指南,并非权威签名来源。
GET /skills/schemaunity_skills.get_skill_schema()