gamedev-unity/skills/unity-skills/skills/prefab/SKILL.md
Manage Prefabs — create, instantiate, apply overrides, unpack, find instances, edit prefab assets, and create variants. Use when working with prefabs, instantiating or applying prefab changes, finding instances in scenes, or creating prefab variants, even if the user just says "做成预制体" or "prefab". 管理 Prefab(创建、实例化、应用覆盖、解包、查找实例、编辑预制体资产、创建变体);当用户要处理预制体、实例化或应用预制体改动、在场景中查找实例、或创建预制体变体时使用。
npx skillsauth add bernatmv/ai-rules unity-prefabInstall 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
prefab_instantiate_batchwhen spawning 2+ prefab instances.
Approval 模式下本模块为 Mixed —— 只读 skill prefab_get_overrides / prefab_find_instances(标 ReadOnly = true, Mode = SkillMode.SemiAuto)可直接执行;其余 9 个写类 skill (prefab_create / prefab_instantiate / prefab_instantiate_batch / prefab_apply / prefab_unpack / prefab_revert_overrides / prefab_apply_overrides / prefab_create_variant / prefab_set_property) 为 SkillMode.FullAuto,需用户 grant 单次执行返结果。Auto / Bypass 直接执行。本模块不含 NeverInSemi 高危 skill(无 Delete / PlayMode / Reload)。
DO NOT (common hallucinations):
prefab_create_from_object does not exist → use prefab_create (takes scene object name/instanceId and savePath)prefab_spawn does not exist → use prefab_instantiateprefab_edit / prefab_modify do not exist → use prefab_set_property (edit prefab asset directly) or instantiate, modify, then prefab_applyprefab_save does not exist → use prefab_apply (applies instance changes to source prefab)Routing:
component module skills, then prefab_applyprefab_set_property (this module)prefab_find_instances (this module)| Single Object | Batch Version | Use Batch When |
|---------------|---------------|----------------|
| prefab_instantiate | prefab_instantiate_batch | Spawning 2+ instances |
No batch needed:
prefab_create - Create prefab from scene objectprefab_apply - Apply instance changes to prefabprefab_unpack - Unpack prefab instanceprefab_get_overrides - Get instance overridesprefab_revert_overrides - Revert to prefab valuesprefab_apply_overrides - Apply overrides to prefabprefab_create_variant - Create a prefab variantprefab_find_instances - Find all instances of a prefab in sceneprefab_set_property - Set a property on a component inside a Prefab asset (supports basic types, vectors, colors, and asset references)Create a prefab from a scene GameObject.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | Source object name |
| instanceId | int | No* | Instance ID (preferred) |
| path | string | No* | Object path |
| savePath | string | Yes | Prefab save path |
*At least one source identifier required.
Returns: {success, prefabPath, sourceObject}
Instantiate a prefab into the scene.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| prefabPath | string | Yes | - | Prefab asset path |
| name | string | No | prefab name | Instance name |
| x, y, z | float | No | 0 | Local position (relative to parent if set) |
| parentEntityId | string | No | null | Parent entity ID (Unity 6000.4+, preferred) |
| parentName | string | No | null | Parent object name |
| parentInstanceId | int | No | 0 | Parent instance ID |
| parentPath | string | No | null | Parent hierarchy path |
Returns: {success, name, entityId, instanceId, path, prefabPath, position}
Instantiate multiple prefabs in one call.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| items | array | Yes | Array of instantiation configs |
Item properties: prefabPath, name, x, y, z, rotX, rotY, rotZ, scaleX, scaleY, scaleZ, parentEntityId, parentName, parentInstanceId, parentPath
Returns: {success, totalItems, successCount, failCount, results: [{success, name, instanceId, prefabPath, position}]}
unity_skills.call_skill("prefab_instantiate_batch", items=[
{"prefabPath": "Assets/Prefabs/Enemy.prefab", "x": 0, "z": 0, "name": "Enemy_01"},
{"prefabPath": "Assets/Prefabs/Enemy.prefab", "x": 2, "z": 0, "name": "Enemy_02"},
{"prefabPath": "Assets/Prefabs/Enemy.prefab", "x": 4, "z": 0, "name": "Enemy_03"}
])
Apply instance changes back to the prefab asset.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | Prefab instance name |
| instanceId | int | No* | Instance ID (preferred) |
| path | string | No* | Object path |
*At least one identifier required.
Returns: {success, gameObject, prefabPath}
Unpack a prefab instance (break prefab connection).
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| name | string | No* | - | Prefab instance name |
| instanceId | int | No* | - | Instance ID (preferred) |
| path | string | No* | - | Object path |
| completely | bool | No | false | Unpack all nested prefabs |
*At least one identifier required.
Returns: {success, gameObject, mode}
Get list of property overrides on a prefab instance.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | Prefab instance name |
| instanceId | int | No* | Instance ID |
Returns: {success, overrides: [{type, path, property}]}
Revert all overrides on a prefab instance back to prefab values.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | Prefab instance name |
| instanceId | int | No* | Instance ID |
Apply all overrides from instance to source prefab asset.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | Prefab instance name |
| instanceId | int | No* | Instance ID |
Create a prefab variant from an existing prefab.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| sourcePrefabPath | string | Yes | - | Path to the source prefab asset |
| variantPath | string | Yes | - | Save path for the new variant |
Returns: { success, sourcePath, variantPath, name }
Find all instances of a prefab in the current scene.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| prefabPath | string | Yes | - | Prefab asset path to search for |
| limit | int | No | 50 | Maximum number of instances to return |
Returns: { success, prefabPath, count, instances: [{ name, path, instanceId }] }
Set a property on a component inside a Prefab asset file (without instantiating it). Supports basic types, vectors, colors, enums, and asset references.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| prefabPath | string | Yes | - | Path to the prefab asset |
| componentType | string | Yes | - | Component type name |
| propertyName | string | Yes | - | Serialized property name |
| value | string | Cond. | null | Value for basic types (int/float/bool/string/enum/vector/color) |
| assetReferencePath | string | Cond. | null | Asset path for Object reference fields (Material, Texture, AudioClip, ScriptableObject, etc.) |
| gameObjectName | string | No | null | Child object name inside prefab (defaults to root) |
Provide either
value(basic types) orassetReferencePath(asset references).
Returns: { success, prefabPath, gameObject, component, property, valueSet }
# Set a float property on prefab root
unity_skills.call_skill("prefab_set_property",
prefabPath="Assets/Prefabs/Enemy.prefab",
componentType="EnemyStats",
propertyName="maxHealth",
value="100"
)
# Assign an asset reference to a prefab component
unity_skills.call_skill("prefab_set_property",
prefabPath="Assets/Prefabs/Enemy.prefab",
componentType="AudioSource",
propertyName="m_audioClip",
assetReferencePath="Assets/Audio/hit.wav"
)
# Edit a child object inside a prefab
unity_skills.call_skill("prefab_set_property",
prefabPath="Assets/Prefabs/Player.prefab",
componentType="MeshRenderer",
propertyName="m_Materials.Array.data[0]",
assetReferencePath="Assets/Materials/PlayerSkin.mat",
gameObjectName="Body"
)
import unity_skills
# BAD: 10 API calls for 10 enemies
for i in range(10):
unity_skills.call_skill("prefab_instantiate",
prefabPath="Assets/Prefabs/Enemy.prefab",
name=f"Enemy_{i}",
x=i * 2
)
# GOOD: 1 API call for 10 enemies
unity_skills.call_skill("prefab_instantiate_batch", items=[
{"prefabPath": "Assets/Prefabs/Enemy.prefab", "name": f"Enemy_{i}", "x": i * 2}
for i in range(10)
])
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 文件或合并冲突。