Unity

Avoid common Unity mistakes — lifecycle ordering, GetComponent caching, physics timing, and Unity's fake null.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "Unity" with this command: npx skills add ivangdavila/unity

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
  • 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

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Power Automate Monitoring

**Pro+ subscription required.** Tenant-wide Power Automate flow health monitoring, failure rate analytics, and asset inventory using the FlowStudio MCP cache...

Registry SourceRecently Updated
General

Power Automate Governance

Govern Power Automate flows and Power Apps at scale using the FlowStudio MCP cached store. Classify flows by business impact, detect orphaned resources, audi...

Registry SourceRecently Updated
General

Secretary Memory

OpenClaw 秘书式多分区记忆系统 v3.0。仿生现代秘书的笔记本分类法,支持:(1) 多分区并发搜索 + 每分区3条上下文召回,(2) 会话自动摘要,(3) 偏好自动提取 + 用户关系图谱,(4) 记忆冲突主动检测,(5) 定时 consolidation + 会话结束 hook,(6) 精细化恢复/回溯,...

Registry SourceRecently Updated
General

运维助手 v2.0

运维助手 v2.0 - 支持本地、远程、多服务器集群监控 (健康检查、日志分析、性能监控、批量操作、文件传输)

Registry SourceRecently Updated