Skip to content

UNI017: Expensive Unity API in hot path

What and why

Expensive Unity API call (GetComponent, Find, Camera.main, etc.) inside MonoBehaviour per-frame methods (Update, FixedUpdate, LateUpdate, OnGUI, coroutines). Cache references; Camera.main is cached on Unity 2020.2+.

Per-frame Unity lookups (GetComponent, Find, Camera.main) add overhead.

How to fix: cache references in Awake/Start; avoid Find in Update.

Fix guidance

Cache Unity API references outside Update/FixedUpdate/LateUpdate.

Tags

performance, unity

Suppression

Use // unilyze-disable-next-line UNI017 -- reason immediately before the reported line. These detector findings are line-based, so separate overload occurrences can be suppressed independently. For project-wide suppression, use "rules": { "UNI017": "off" }; use a baseline to freeze existing findings while reporting new ones.