Iván
作者:Iván更新於 2026-05-11unity@clawhub_ivangdavila/unity
程式碼生成Bug 修復

據 AlphaMoat 統計,截至 2026-09,Unity 累計下載 3,823 次、獲 5 個星標,在全部 5,078 個 AI 技能中排名第 2,751 位,在「開發程式設計」分類(577 個)中排名第 359 位。

累計安裝
368
累計下載
3823
星標
5
全站排名
#2,751
全站前 55% · 「開發程式設計」前 63%
平台累計安裝累計下載星標評論
ClawHub ↗9030123-
SkillHub ↗36838235—

各平台的計數口徑不同,統計時間不一致。

這個技能是做什麼的

內容包括元件引用快取、初始化順序、物理更新時序、已銷燬物件的 null 行為、協程、物件池、序列化及 ScriptableObjects。應結合實際專案與 Unity 行為作為審查清單,不代表程式碼已經過測試或效能最佳化。

資料釋出於 2026-10-27

可以用來做什麼

  • 檢查 Unity 指令碼的生命週期與分配問題

什麼時候用

  • 需要審查遊戲程式碼、物理時序或物件複用時

示例提示詞

以下是根據技能文件生成的示例,不代表實際執行結果。

檢查這個 Unity 指令碼的初始化、重複元件查詢、物理時序及已銷燬物件判空。

月度資料趨勢

累計下載3823
1564277739902026-03 · 累計下載 17312026-05 · 累計下載 22532026-06 · 累計下載 24142026-07 · 累計下載 27162026-08 · 累計下載 30002026-09 · 累計下載 382326-0326-09
星標5
3452026-03 · 星標 32026-05 · 星標 32026-06 · 星標 32026-07 · 星標 42026-08 · 星標 42026-09 · 星標 526-0326-09

2026-09 起統計方法調整:同名技能按作者分別統計,並覆蓋全部技能。圖中虛線為調整前的月份,與之後的資料不直接比較,也不計算跨越調整的增長。

月份累計下載環比星標
2026-093823—5
2026-083000+10.5%4
2026-072716+12.5%4
2026-062414+7.1%3
2026-052253—3
2026-031731—3

SKILL.md 原文

以下是作者釋出的原始檔案,按純文字顯示,本站未做修改或稽核;其中的連結不可點選,命令請核實後再執行。抓取於 2026-10-23。

3.1 KB · ClawHub v1.0.0
---
name: Unity
description: Avoid common Unity mistakes — lifecycle ordering, GetComponent caching, physics timing, and Unity's fake null.
metadata: {"clawdbot":{"emoji":"🎮","os":["linux","darwin","win32"]}}
---

## Lifecycle Order
- `Awake` before `Start` — use Awake for self-init, Start for cross-references
- `OnEnable` called before `Start` — but after `Awake`
- Order between scripts not guaranteed — use Script Execution Order if needed
展開全部(共 61 行)
- `Awake` called even if disabled — `Start` only when enabled

## GetComponent Performance
- `GetComponent` every frame is slow — cache in `Awake` or `Start`
- `GetComponentInChildren` searches recursively — expensive on deep hierarchies
- `TryGetComponent` returns bool — avoids null check, slightly faster
- Use `RequireComponent` attribute — ensures dependency, documents requirement

## Physics Timing
- Physics in `FixedUpdate`, not `Update` — consistent regardless of framerate
- `FixedUpdate` can run 0 or multiple times per frame — don't assume 1:1
- `Rigidbody.MovePosition` in FixedUpdate — `transform.position` bypasses physics
- `Time.deltaTime` in Update, `Time.fixedDeltaTime` in FixedUpdate — or just use deltaTime

## Unity's Fake Null
- Destroyed objects aren't truly null — `== null` returns true, but object exists
- Null-conditional `?.` doesn't work properly — use `== null` or `bool` conversion
- `Destroy` doesn't happen immediately — object gone next frame
- Use `DestroyImmediate` only in editor — causes issues in builds

## Coroutines
- `StartCoroutine` needs MonoBehaviour active — disabled/destroyed stops coroutines
- `yield return null` waits one frame — `yield return new WaitForSeconds(1)` for time
- `StopCoroutine` needs same method or Coroutine reference — string overload unreliable
- Can't return values — use callbacks or set field in coroutine

## Instantiate and Pooling
- `Instantiate` is expensive — pool frequently created/destroyed objects
- `Instantiate(prefab, parent)` sets parent — avoids extra SetParent call
- `SetActive(false)` before returning to pool — not Destroy
- Pool inactive objects under a parent — keeps hierarchy clean

## Serialization
- `[SerializeField]` for private fields in inspector — prefer over public
- `public` fields auto-serialize — but exposes API you may not want
- `[HideInInspector]` hides but still serializes — `[NonSerialized]` to skip entirely
- Serialized fields keep inspector values — code defaults ignored after first serialize

## ScriptableObjects
- Data containers that live as assets — share between scenes/prefabs
- `CreateAssetMenu` attribute for easy creation — right-click → Create
- Don't modify at runtime in builds — changes not saved (except in editor)
- Great for config, item databases — reduces prefab duplication

## Common Mistakes
- `Find` methods every frame — cache references
- String comparisons for tags — use `CompareTag("Enemy")`, not `tag == "Enemy"`
- Physics queries allocate — use `NonAlloc` variants: `RaycastNonAlloc`
- UI anchors wrong — stretches unexpectedly on different resolutions
- `async/await` without context — use UniTask or careful error handling

「開發程式設計」分類下的熱門技能

Iván 的其他技能

資料月份:2026-09 · 下載/星標/安裝數聚合自公開技能註冊庫(ClawHub、SkillHub),按月更新。口徑說明見資料方法。