gamedev-unity/skills/unity-skills/skills/material/SKILL.md
Edit Unity material and shader properties across Built-in/URP/HDRP — colors, textures, floats, keywords, render queue, batch-apply. Use when changing how a surface looks, tweaking material parameters, or swapping shaders. 编辑材质与 Shader 属性(Built-in/URP/HDRP:颜色、贴图、浮点值、关键字、渲染队列、批量应用);当用户要调整物体外观、改材质参数或切换 Shader 时使用。
npx skillsauth add bernatmv/ai-rules unity-materialInstall 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/materials.
material_create, material_create_batch, material_assign, material_assign_batch, material_duplicate, material_set_color / _emission / _texture / _float / _int / _vector / _keyword / _render_queue / _shader / _texture_offset / _texture_scale / _gi_flags, and the *_batch variants) need user grant; grant triggers a single server-side execution that returns the result.material_get_properties, material_get_keywords) are SkillMode.SemiAuto — they run in all three modes without grant.asset module.DO NOT (common hallucinations):
material_set_metallic / material_set_smoothness do not exist → use material_set_float with propertyName="_Metallic" or "_Glossiness" (Standard) / "_Smoothness" (URP)material_set_color r/g/b/a range is 0–1, not 0–255material_set_property does not exist → use the specific setter: material_set_float, material_set_int, material_set_vector, material_set_colormaterial_get_color does not exist → use material_get_properties (returns all properties including colors)Routing:
material_set_shader (this module)material_set_texture_scale / material_set_texture_offsetObject Targeting: Most single-object skills accept
name(GameObject name) orpath. Behaviour ofpath:
- In
material_set_*/material_get_*(color/emission/texture/float/int/vector/keyword/shader/render_queue/gi_flags/properties),pathmay be either a GameObject hierarchy path or a material asset path likeAssets/Materials/X.mat— the skill auto-detects (paths starting withAssets/or ending with.matare treated as material assets).- In
material_assign,pathis a GameObject hierarchy path only; the material to assign goes in the separatematerialPathparameter.
| Single Object | Batch Version | Use Batch When |
|---------------|---------------|----------------|
| material_create | material_create_batch | Creating 2+ materials |
| material_assign | material_assign_batch | Assigning to 2+ objects |
| material_set_color | material_set_colors_batch | Setting colors on 2+ objects |
| material_set_emission | material_set_emission_batch | Setting emission on 2+ objects |
No batch needed:
material_set_texture - Set texturematerial_set_texture_offset/scale - Texture tilingmaterial_set_float/int/vector - Set propertiesmaterial_set_keyword - Enable/disable shader keywordsmaterial_set_render_queue - Set render queuematerial_set_shader - Change shadermaterial_get_properties/keywords - Query propertiesmaterial_duplicate - Duplicate materialCreate a new material (auto-detects render pipeline).
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| name | string | Yes | - | Material name |
| shaderName | string | No | auto-detect | Shader (auto-detects URP/HDRP/Standard) |
| savePath | string | No | null | Save path (folder or full path) |
Create multiple materials.
| 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, name, path}]}
unity_skills.call_skill("material_create_batch", items=[
{"name": "Red", "savePath": "Assets/Materials"},
{"name": "Blue", "savePath": "Assets/Materials"},
{"name": "Green", "savePath": "Assets/Materials"}
])
Assign material to object's renderer.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| instanceId | int | No* | Instance ID |
| path | string | No* | GameObject hierarchy path |
| materialPath | string | Yes | Material asset to assign (e.g. Assets/Materials/X.mat) |
Assign materials 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, name, materialPath}]}
unity_skills.call_skill("material_assign_batch", items=[
{"name": "Cube1", "materialPath": "Assets/Materials/Red.mat"},
{"name": "Cube2", "materialPath": "Assets/Materials/Blue.mat"}
])
Set material color with optional HDR intensity.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
| r, g, b | float | No | 1 | Color (0-1) |
| a | float | No | 1 | Alpha |
| propertyName | string | No | auto-detect | Color property |
| intensity | float | No | 1.0 | HDR intensity (>1 for bloom) |
Set colors on multiple objects. Each item accepts: identifier (name/instanceId/path) + r, g, b, a, optional per-item propertyName.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| items | json string | Yes | - | JSON array of {name|instanceId|path, r, g, b, a} per-item objects (see example below) |
| propertyName | string | No | auto-detect | Default color property applied to all items unless overridden |
Returns: {success, totalItems, successCount, failCount, results: [{success, name}]}
unity_skills.call_skill("material_set_colors_batch", items=[
{"name": "Cube1", "r": 1, "g": 0, "b": 0},
{"name": "Cube2", "r": 0, "g": 1, "b": 0},
{"name": "Cube3", "r": 0, "g": 0, "b": 1}
])
Set emission color with auto-enable keyword.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
| r, g, b | float | No | 1 | Emission color (0-1) |
| intensity | float | No | 1.0 | HDR intensity (>1 for bloom) |
| enableEmission | bool | No | true | Auto-enable _EMISSION keyword |
Set emission 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, name}]}
unity_skills.call_skill("material_set_emission_batch", items=[
{"name": "Neon1", "r": 1, "g": 0, "b": 1, "intensity": 5.0},
{"name": "Neon2", "r": 0, "g": 1, "b": 1, "intensity": 5.0}
])
Set material texture.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
| texturePath | string | Yes | - | Texture asset path |
| propertyName | string | No | auto-detect | Texture property |
Set a float property on a material.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
| propertyName | string | Yes | Property name |
| value | float | Yes | Value |
Set an integer property on a material.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
| propertyName | string | Yes | Property name |
| value | int | Yes | Value |
Enable/disable shader keywords.
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
| keyword | string | Yes | - | Keyword name |
| enable | bool | No | true | Enable or disable |
Common Keywords: _EMISSION, _NORMALMAP, _METALLICGLOSSMAP, _ALPHATEST_ON, _ALPHABLEND_ON
Get all material properties.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
Returns: {success, target, shader, renderQueue, keywords, giFlags, properties: {colors, floats, vectors, textures, integers}}
Get all enabled shader keywords on a material.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
Duplicate a material asset.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| sourcePath | string | Yes | Source material path |
| newName | string | Yes | Name for the duplicated material |
| savePath | string | No | Optional folder/path override for the duplicated material |
Change the shader of a material.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
| shaderName | string | Yes | Shader name |
Set a Vector4 property on a material.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
| propertyName | string | Yes | Property name |
| x, y, z, w | float | Yes | Vector components |
Set texture offset (tiling position).
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
| propertyName | string | No | Texture property name |
| x, y | float | Yes | Offset values |
Set texture scale (tiling).
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
| propertyName | string | No | Texture property name |
| x, y | float | Yes | Scale values |
Set material render queue.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | Material asset path |
| renderQueue | int | Yes | Render queue value |
Set material global illumination flags.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name | string | No* | GameObject name |
| path | string | No* | GameObject hierarchy path or material asset path |
| flags | string | Yes | GI flags: None / RealtimeEmissive / BakedEmissive / EmissiveIsBlack / AnyEmissive (default RealtimeEmissive if omitted in code; required here)
import unity_skills
# BAD: 6 API calls
unity_skills.call_skill("material_create", name="Mat1", savePath="Assets/Materials")
unity_skills.call_skill("material_create", name="Mat2", savePath="Assets/Materials")
unity_skills.call_skill("material_set_color", path="Assets/Materials/Mat1.mat", r=1, g=0, b=0)
unity_skills.call_skill("material_set_color", path="Assets/Materials/Mat2.mat", r=0, g=0, b=1)
unity_skills.call_skill("material_assign", name="Cube1", materialPath="Assets/Materials/Mat1.mat")
unity_skills.call_skill("material_assign", name="Cube2", materialPath="Assets/Materials/Mat2.mat")
# GOOD: 3 API calls
unity_skills.call_skill("material_create_batch", items=[
{"name": "Mat1", "savePath": "Assets/Materials"},
{"name": "Mat2", "savePath": "Assets/Materials"}
])
unity_skills.call_skill("material_set_colors_batch", items=[
{"path": "Assets/Materials/Mat1.mat", "r": 1, "g": 0, "b": 0},
{"path": "Assets/Materials/Mat2.mat", "r": 0, "g": 0, "b": 1}
])
unity_skills.call_skill("material_assign_batch", items=[
{"name": "Cube1", "materialPath": "Assets/Materials/Mat1.mat"},
{"name": "Cube2", "materialPath": "Assets/Materials/Mat2.mat"}
])
Skills auto-detect and adapt to your render pipeline:
| Pipeline | Default Shader | Color Property | Texture Property |
|----------|---------------|----------------|------------------|
| Built-in | Standard | _Color | _MainTex |
| URP | Universal Render Pipeline/Lit | _BaseColor | _BaseMap |
| HDRP | HDRP/Lit | _BaseColor | _BaseColorMap |
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 文件或合并冲突。