gamedev-unity/skills/unity-skills/skills/component/SKILL.md
Manage GameObject components — add, remove, list, copy, enable/disable, and read/set component fields. Use when attaching or removing components, copying components between objects, toggling them, or reading/writing their serialized fields, even if the user just says "加个组件" or "改组件属性". 管理 GameObject 组件(添加、移除、列出、复制、启用/禁用、读写组件字段);当用户要挂载或移除组件、在对象间复制组件、开关组件或读写其序列化字段时使用。
npx skillsauth add bernatmv/ai-rules unity-componentInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
BATCH-FIRST: Use
*_batchskills when operating on 2+ objects to reduce API calls from N to 1.
component_list / component_get_properties 标 SkillMode.SemiAuto,可直接执行;写类 skill (component_add / component_set_property / component_set_enabled / component_copy 等) 标 SkillMode.FullAuto,需 grant 单次执行返结果。component_remove / component_remove_batch(Operation.Delete)。这些在 Approval/Auto 下返 MODE_FORBIDDEN,仅 Bypass 或 Allowlist 命中可调。DO NOT (common hallucinations):
component_create / component_get do not exist → use component_add (add) and component_get_properties (read)component_find does not exist → use component_list to list components on an objectcomponentType is case-sensitive — Rigidbody not rigidbody, BoxCollider not boxcolliderNamespace.ClassNameRouting:
script module's script_create first, then component_addcomponent_set_property_batchcomponent_set_enabled (not component_set_property)Object Targeting: All single-object skills accept
name(string),instanceId(int, preferred), andpath(string, hierarchy path). Provide at least one.
| Single Object | Batch Version | Use Batch When |
|---------------|---------------|----------------|
| component_add | component_add_batch | Adding to 2+ objects |
| component_remove | component_remove_batch | Removing from 2+ objects |
| component_set_property | component_set_property_batch | Setting on 2+ objects |
| component_set_serialized_property | component_set_serialized_property_batch | Setting Inspector SerializedProperty paths |
Other Skills (no batch):
component_list - List all components on an objectcomponent_get_properties - Get component property valuescomponent_set_enabled - Enable/disable a component (Behaviour, Renderer, Collider)component_copy - Copy a component from one object to anothercomponent_get_serialized_properties - List Inspector SerializedProperty pathscomponent_copy_exact - Copy a component and verify serialized fields matchAdd a component to a GameObject.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| instanceId | int | No* | Instance ID (preferred) |
| path | string | No* | Hierarchy path |
| componentType | string | Yes | Component type name |
*At least one identifier required
Returns: {success, gameObject, instanceId, component, fullTypeName} (returns {warning, gameObject, instanceId} instead if a single-instance component already exists)
Remove a component from a GameObject.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| instanceId | int | No* | Instance ID |
| componentType | string | Yes | Component type to remove |
Returns: {success, gameObject, removed} (removed is the requested componentType string)
List all components on a GameObject.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| instanceId | int | No* | Instance ID |
Returns: {gameObject, instanceId, path, componentCount, components: [{type, fullType, enabled, keyProperties?}]} (keyProperties only present when includeProperties=true)
Set a component property value.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| instanceId | int | No* | Instance ID |
| componentType | string | Yes | Component type |
| propertyName | string | Yes | Property to set |
| value | any | Cond. | New value (for basic types, vectors, colors) |
| referencePath | string | No | Scene object hierarchy path (for scene references) |
| referenceName | string | No | Scene object name (for scene references) |
| assetPath | string | No | Project asset path (for asset references: Material, Texture, AudioClip, ScriptableObject, Prefab, etc.) |
Provide one of:
value(basic types),referencePath/referenceName(scene objects), orassetPath(project assets).
value type examples:
# float / int / bool / string
call_skill("component_set_property", name="Obj", componentType="Rigidbody", propertyName="mass", value=2.5)
call_skill("component_set_property", name="Obj", componentType="Rigidbody", propertyName="useGravity", value=False)
# Vector3 (JSON object with x, y, z)
call_skill("component_set_property", name="Obj", componentType="Transform", propertyName="localPosition",
value={"x": 1, "y": 2, "z": 3})
# Color (JSON object with r, g, b, a — values 0-1)
call_skill("component_set_property", name="Obj", componentType="Light", propertyName="color",
value={"r": 1, "g": 0.5, "b": 0, "a": 1})
# Enum (use string name)
call_skill("component_set_property", name="Obj", componentType="Rigidbody", propertyName="interpolation",
value="Interpolate")
Returns: {success, gameObject, component, property, valueSet, valueType} (valueSet is the string form of the actual value applied; valueType is the resolved target type name)
Get all properties of a component.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| instanceId | int | No* | Instance ID |
| componentType | string | Yes | Component type |
Returns: {gameObject, component, fullTypeName, properties: [{name, type, fullType, value, canWrite}], fields: [{name, type, fullType, value, isSerializable}]}
List Inspector serialized properties on a component via SerializedObject.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| instanceId | int | No* | Instance ID |
| path | string | No* | Hierarchy path |
| componentType | string | Yes | Component type |
| includeChildren | bool | No | Include nested properties |
| limit | int | No | Max properties returned |
Returns: {success, gameObject, component, fullTypeName, properties}
Set an Inspector serialized property by propertyPath.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| instanceId | int | No* | Instance ID |
| path | string | No* | Hierarchy path |
| componentType | string | Yes | Component type |
| propertyPath | string | Yes | SerializedProperty path, e.g. items.Array.data[0] |
| value | string | Cond. | Primitive/vector/color/enum value |
| referenceName | string | No | Scene object name for ObjectReference |
| referenceInstanceId | int | No | Scene object instance ID for ObjectReference |
| referencePath | string | No | Scene object path for ObjectReference |
| assetPath | string | No | Project asset path for ObjectReference |
| objectType | string | No | Expected object/component type for references |
Provide
valuefor scalar properties, or a scene/project reference for ObjectReference fields.
Returns: {success, gameObject, component, propertyPath, valueSet}
Add components to multiple objects.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| items | json string | Yes | - | JSON array of per-item objects (see example below) |
Returns: {success, totalItems, successCount, failCount, results: [{success, gameObject, componentType, added}]}
unity_skills.call_skill("component_add_batch", items=[
{"name": "Enemy1", "componentType": "Rigidbody"},
{"name": "Enemy2", "componentType": "Rigidbody"},
{"name": "Enemy3", "componentType": "Rigidbody"}
])
Remove components from multiple objects.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| items | json string | Yes | - | JSON array of per-item objects (see example below) |
Returns: {success, totalItems, successCount, failCount, results: [{success, gameObject, componentType, removed}]}
unity_skills.call_skill("component_remove_batch", items=[
{"instanceId": 12345, "componentType": "BoxCollider"},
{"instanceId": 12346, "componentType": "BoxCollider"}
])
Set properties on multiple objects.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| items | json string | Yes | - | JSON array of per-item objects (see example below) |
Returns: {success, totalItems, successCount, failCount, results: [{success, gameObject, componentType, property, oldValue, newValue}]}
unity_skills.call_skill("component_set_property_batch", items=[
{"name": "Enemy1", "componentType": "Rigidbody", "propertyName": "mass", "value": 2.0},
{"name": "Enemy2", "componentType": "Rigidbody", "propertyName": "mass", "value": 2.0}
])
Set Inspector serialized properties on multiple components.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| items | json string | Yes | - | JSON array of per-item objects |
Item properties: name, instanceId, path, componentType, propertyPath, value, referenceName, referenceInstanceId, referencePath, assetPath, objectType
Returns: {success, totalItems, successCount, failCount, results}
| Type | Description |
|------|-------------|
| Rigidbody | Physics simulation |
| BoxCollider | Box collision |
| SphereCollider | Sphere collision |
| CapsuleCollider | Capsule collision |
| MeshCollider | Mesh-based collision |
| CharacterController | Character movement |
| Type | Description |
|------|-------------|
| MeshRenderer | Render meshes |
| SkinnedMeshRenderer | Animated meshes |
| SpriteRenderer | 2D sprites |
| LineRenderer | Draw lines |
| TrailRenderer | Motion trails |
| Type | Description |
|------|-------------|
| AudioSource | Play sounds |
| AudioListener | Receive audio |
| Type | Description |
|------|-------------|
| Canvas | UI container |
| Image | UI images |
| Text | UI text (legacy) |
| Button | Clickable button |
import unity_skills
# BAD: 6 API calls
unity_skills.call_skill("component_add", name="Box1", componentType="Rigidbody")
unity_skills.call_skill("component_add", name="Box2", componentType="Rigidbody")
unity_skills.call_skill("component_add", name="Box3", componentType="Rigidbody")
unity_skills.call_skill("component_set_property", name="Box1", componentType="Rigidbody", propertyName="mass", value=2.0)
unity_skills.call_skill("component_set_property", name="Box2", componentType="Rigidbody", propertyName="mass", value=2.0)
unity_skills.call_skill("component_set_property", name="Box3", componentType="Rigidbody", propertyName="mass", value=2.0)
# GOOD: 2 API calls
unity_skills.call_skill("component_add_batch", items=[
{"name": "Box1", "componentType": "Rigidbody"},
{"name": "Box2", "componentType": "Rigidbody"},
{"name": "Box3", "componentType": "Rigidbody"}
])
unity_skills.call_skill("component_set_property_batch", items=[
{"name": "Box1", "componentType": "Rigidbody", "propertyName": "mass", "value": 2.0},
{"name": "Box2", "componentType": "Rigidbody", "propertyName": "mass", "value": 2.0},
{"name": "Box3", "componentType": "Rigidbody", "propertyName": "mass", "value": 2.0}
])
component_list to verify additionscomponent_get_properties firstcomponent_copyCopy a component from one GameObject to another.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| sourceName | string | No* | null | Source GameObject name |
| sourceInstanceId | int | No* | 0 | Source Instance ID |
| sourcePath | string | No* | null | Source hierarchy path |
| targetName | string | No* | null | Target GameObject name |
| targetInstanceId | int | No* | 0 | Target Instance ID |
| targetPath | string | No* | null | Target hierarchy path |
| componentType | string | Yes | - | Component type to copy |
*At least one source identifier and one target identifier required
Returns: { success, source, target, componentType }
component_copy_exactCopy a component from one GameObject to another and verify serialized Inspector fields match.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| sourceName | string | No* | null | Source GameObject name |
| sourceInstanceId | int | No* | 0 | Source Instance ID |
| sourcePath | string | No* | null | Source hierarchy path |
| targetName | string | No* | null | Target GameObject name |
| targetInstanceId | int | No* | 0 | Target Instance ID |
| targetPath | string | No* | null | Target hierarchy path |
| componentType | string | Yes | - | Component type to copy |
Returns: { success, source, target, componentType, verified, mismatchCount, mismatches? }
component_set_enabledEnable or disable a component (Behaviour, Renderer, Collider, etc.).
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| name | string | No* | null | GameObject name |
| instanceId | int | No* | 0 | Instance ID |
| path | string | No* | null | Hierarchy path |
| componentType | string | Yes | - | Component type to enable/disable |
| enabled | bool | No | true | Whether to enable or disable |
*At least one identifier required
Returns: { success, gameObject, componentType, enabled }
Exact names, parameters, defaults, and returns are defined by GET /skills/schema or unity_skills.get_skill_schema(), not by this file.
development
Keyword research and validation with real search-demand data — never ship keywords from intuition alone. Probes Google Autocomplete per language (free, no account) to prove demand and discover the exact phrasing people type, checks SERPs for winnability, and uses Keyword Planner/Ahrefs/Semrush exports when the user has access. Activates when: choosing or reviewing SEO keywords, meta keywords, page titles, article topics or slugs, landing page copy targeting search, App Store/ASO keyword fields, multilingual keyword sets, 'what should we rank for', 'keyword analysis', or auditing why a page doesn't rank. Also invoke it as a validation pass whenever another skill or task produces a keyword list.
development
Automate YooAsset hot-update and asset bundles — build bundles, run Editor simulate builds, manage Collector groups, analyze BuildReport, and validate runtime. Use when building or simulating YooAsset bundles, configuring collectors, or validating hot-update assets, even if the user just says "热更" or "打AB包". 自动化 YooAsset 热更新与资源包(构建 bundle、编辑器模拟构建、管理 Collector 分组、分析 BuildReport、运行时校验);当用户要构建或模拟 YooAsset 资源包、配置 collector、或校验热更资源时使用。
development
Source-anchored design rules for YooAsset v2.3.18 — initialization, default-package shortcuts, play modes, asset handles, loading, updates, filesystem, build, and pitfalls. Use when writing or reviewing YooAsset code, initializing packages, loading assets via handles, setting up hot-update/download, or choosing a play mode, even if the user just says "热更" or "资源包". 为 YooAsset v2.3.18 提供源码锚定的设计规则(初始化、默认包快捷方式、运行模式、资源句柄、加载、更新、文件系统、构建、陷阱);当用户要编写或审查 YooAsset 代码、初始化 package、用句柄加载资源、配置热更/下载、或选择运行模式时使用。
data-ai
Last-resort guidance for safely hand-editing Unity serialized YAML (.unity/.prefab/.asset/.meta/ProjectSettings) — reference/fileID repair, GUID safety, and merge-conflict fixes. Use when REST cannot reach the change and YAML must be hand-edited — fixing m_Script GUIDs, broken fileID references, .meta files, or merge conflicts, even if the user just says "场景文件打不开" or "引用丢了". 安全手编 Unity 序列化 YAML(.unity/.prefab/.asset/.meta/ProjectSettings)的最后手段(引用/fileID 修复、GUID 安全、合并冲突修复);当 REST 无法触达、必须手编 YAML 时使用——修复 m_Script GUID、断裂 fileID 引用、.meta 文件或合并冲突。