unity-csharp

unity-csharp is a skill for Claude Code, Codex from Wade-DevCode/awesome-coding-skills-cn. It costs 28 tokens per session (2,931 once invoked), scanned A, original, MIT.

A set of practical guidelines for writing Unity game scripts in C#. Unity is a game engine, and these rules cover its update loop, object lifetime, memory cleanup, coroutines, and editable data.

In plain words
What is it for?
Use it when creating or reviewing Unity MonoBehaviour and ScriptableObject scripts. It helps with performance tuning, coroutine problems, object pooling, serialization, and safe cleanup.
Why use it?
It helps avoid frame-rate drops, repeated event handlers, memory leaks, excessive garbage collection, and lifecycle-order bugs. It also clarifies when to use per-frame code, events, or timed routines.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when creating or reviewing Unity MonoBehaviour and ScriptableObject scripts. It helps with performance tuning, coroutine problems, object pooling, serialization, and safe cleanup.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/wade-devcode/awesome-coding-skills-cn/unity-csharp
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add Wade-DevCode/awesome-coding-skills-cn --skill unity-csharp
Clone the repo
git clone --depth 1 https://github.com/Wade-DevCode/awesome-coding-skills-cn

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for unity-csharp

README.md
[![agentmods](https://agentmods.dev/badge/skills/wade-devcode/awesome-coding-skills-cn/unity-csharp/github.svg)](https://agentmods.dev/skills/wade-devcode/awesome-coding-skills-cn/unity-csharp)
Your own site
<a href="https://agentmods.dev/skills/wade-devcode/awesome-coding-skills-cn/unity-csharp"><img src="https://agentmods.dev/badge/skills/wade-devcode/awesome-coding-skills-cn/unity-csharp/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for unity-csharp

Your own site · 80×15
<a href="https://agentmods.dev/skills/wade-devcode/awesome-coding-skills-cn/unity-csharp"><img src="https://agentmods.dev/badge/skills/wade-devcode/awesome-coding-skills-cn/unity-csharp.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 28 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,931 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00028 $0.02931
Opus 5.5 $0.00011 $0.01172
Sonnet 5.5 $0.00006 $0.00586
Haiku 4.5 $0.00003 $0.00293

Measured 1mo ago against content hash 4715e549708f, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

unity-csharp scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/unity-csharp/SKILL.md · 198 lines

How it starts

The opening of the file, as written. The whole thing — 198 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Unity C# 最佳实践

何时用

  • 开始编写任何 Unity MonoBehaviour 或 ScriptableObject 脚本前。
  • Review 他人 Unity C# 代码,发现有 Update 里调 GetComponent 或每帧 new 对象时。
  • 接到性能优化任务:帧率抖动、GC Alloc 频繁、Profiler 里 Update 调用栈过深。
  • 设计新的配置数据结构,考虑用 ScriptableObject 还是 public 字段时。
  • 协程逻辑出现卡死、泄漏、或销毁对象后仍在跑的诡异现象时。

核心规则

1. 慎用 Update:每帧逻辑最小化

规则: Update 里只放真正需要每帧响应的逻辑;能用事件、协程或 InvokeRepeating 驱动的,就不放进 Update;任何 GetComponent、Find、tag 比较一律在 Awake/Start 里缓存,不在 Update 里调用。

为什么: AI 和新手最常见的模式是把所有逻辑堆进 Update——"反正每帧都会跑到"。结果是:GetComponent 每帧反射查找,100 个对象就是 100 次反射;倒计时用 timer -= Time.deltaTime 没问题,但 UI 刷新、动画触发、状态机判断全挤在里面,Profiler 一看 Update 占 80% CPU。更隐蔽的问题:新人把 FindObjectOfType<GameManager>() 放进 Update,场景里一有几十个对象就掉帧,排查时根本不知道从哪查。

怎么做:

  • 初始化引用全部放 Awake(自身组件)或 Start(跨对象引用)。
  • 定时逻辑用 InvokeRepeating 或协程 WaitForSeconds,不用 Update 里的计数器模拟低频事件。
  • 状态变化用 C# event / UnityEvent 通知,订阅方在变化时响应,而不是每帧 poll if (state == X)。
  • 真正需要每帧的(移动插值、输入读取),保留在 Update,但代码量要极简,复杂运算提取为方法并在注释说明频率必要性。

2. 防 GC 抖动:高频路径零分配

规则: Update、FixedUpdate、协程的热路径里禁止出现 new(含 LINQ、字符串拼接、装箱);高频复用的对象用对象池管理;容器在初始化时预分配容量。

为什么: Unity 使用 Mono / IL2CPP 的 GC,GC 触发时会造成明显的帧率刺尖(spike)。AI 写的代码里最常见的杀手:string.Format($"Score: {score}") 每帧执行一次,enemies.Where(e => e.isAlive).ToList() 每帧生成一个新 List,new Vector3(...) 看起来是值类型不会 GC——但装箱到 object 参数时就会。新手则喜欢在子弹生成时 Instantiate、销毁时 Destroy,百发子弹就是百次 GC 压力。

怎么做:

  • 用 StringBuilder 或 TMP_Text.SetText(format, arg) 替代字符串拼接。
  • LINQ 仅用于编辑器工具或低频初始化代码,运行时热路径改用显式 for 循环。
  • 子弹、特效、UI 元素用 ObjectPool<T>(Unity 2021+ 内置)或自实现的栈式对象池。
  • 用 List<T>(initialCapacity) 预分配,避免频繁扩容。
  • 用 Unity Profiler 的 Memory 视图确认改动前后 GC Alloc 列清零。

3. 协程与生命周期:时序清楚,防泄漏

规则: 明确 Awake → OnEnable → Start → Update → OnDisable → OnDestroy 的时序;协程在对象 SetActive(false) 或 OnDisable 时自动停止,但 OnDestroy 时不会自动停止跑在其他 MonoBehaviour 上的协程;协程引用必须在 OnDisable/OnDestroy 里主动 StopCoroutine。

为什么: AI 最典型的错误:在 Awake 里启动协程并访问 Start 才会初始化完毕的跨组件引用,导致 NullReferenceException;或者在 OnDestroy 不清理,导致协程持有对已销毁对象的引用,每帧报 MissingReferenceException,但对象本体早就没了,难以溯源。新手则习惯用 StartCoroutine 后不记返回值,后来想停却只能 StopAllCoroutines,误杀其他协程。

Read the full file on GitHub · 198 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 198 lines · 28 tokens per session scan A 4715e549708f

Subscribe to this mod's changes

unity-csharp is a skill published in the GitHub repository Wade-DevCode/awesome-coding-skills-cn (7 stars, last pushed 4mo ago), licensed MIT. It adds 28 tokens to every session and 2,931 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

script-execute

Compiles and executes C# code dynamically using Roslyn. Supports a full-code mode (default) and a body-only mode — see the skill body for the difference and for how to pass Unity object references as parameters.

IvanMurzak/Unity-MCP · 48 tokens

script-read

Read a .cs script file and return its content as a string. Supports a 1-based lineFrom/lineTo slice for partial reads. Pair with 'script-update-or-create' to write back.

IvanMurzak/Unity-MCP · 49 tokens

script-update-or-create

Write a .cs script file (create or overwrite) with the provided C# code. Validates syntax via Roslyn before write — invalid code is rejected with error details and the file is left untouched. Refreshes the AssetDatabase and delivers the final result via requestId after Unity finishes the triggered compilation. Use…

IvanMurzak/Unity-MCP · 80 tokens

script-delete

Delete one or more .cs script files from disk, refresh the AssetDatabase, and wait for Unity compilation to settle before delivering the final result via the request's requestId. Pair with 'script-read' to inspect files before deletion.

IvanMurzak/Unity-MCP · 52 tokens

game-development

Expert guidance for game development with C#/Unity, Lua scripting, and best practices for scalable game architecture.

Mindrally/skills · 23 tokens

stream-unity

Build, integrate, and answer how-to questions for Stream Chat and Stream Video in Unity Engine games and apps. Use for Unity / C# / MonoBehaviour project work - the Chat .unitypackage and the Video UPM package, StreamChatClient / StreamVideoClient wiring, ConnectUserAsync and tokens, channels and messages, calls and…

GetStream/agent-skills · 211 tokens