MIG.FindObjectOfType
FindObjectOfType is deprecated in Unity 2023.1 and Unity 6
Unity deprecated FindObjectOfType and FindObjectsOfType in 2023.1 (so also in Unity 6) in favour of a family that makes the sorting cost explicit. The compiler warning tells you it’s obsolete; it doesn’t tell you which replacement you want, and the two options behave differently.
The replacements
| Old | New | Notes |
|---|---|---|
FindObjectOfType<T>() | FindAnyObjectByType<T>() | Faster; no order guarantee — returns any match |
FindObjectOfType<T>() | FindFirstObjectByType<T>() | Matches the old ordering behaviour; slower |
FindObjectsOfType<T>() | FindObjectsByType<T>(FindObjectsSortMode.None) | Unsorted, and the faster default |
FindAnyObjectByType is what most call sites actually want — “find the one AudioManager in the scene” doesn’t care about order. Reach for FindFirstObjectByType only where the code genuinely depends on getting a deterministic first match, which is rare and usually accidental.
For FindObjectsOfType, passing FindObjectsSortMode.None skips the sort the old API always paid for. If you were relying on the sorted order, FindObjectsSortMode.InstanceID reproduces it.
What the scan looks at
Runtime C# under Assets/, matched per file and line, and only reported on Unity 2023.1 or newer — on 2021/2022 these APIs are not deprecated, and flagging them would be noise for someone who isn’t upgrading.
While you’re in there
Both APIs walk the scene graph. If they’re being called in Update, the deprecation is the smaller problem: cache the reference in Awake/Start, or inject it, and the call disappears from your frame budget entirely. A deprecation pass is a good moment to notice that.
What PerfLint does about it
This one is safely automatable, and it’s one of the few migration rules where AI fix is allowed: the replacement is a rename-style edit, so substituting the flagged fragment is sufficient and can’t strand downstream code. The fix is proposed as a diff you approve before anything is written, and only the snippet in question is sent to the model — the scan itself never uploads anything.
Structural migrations are treated differently on purpose. WWW → UnityWebRequest, GUIText → UGUI, and the legacy particle system change the whole surrounding block; those rules report and locate, and explicitly refuse an automatic fix, because a local fragment replacement would corrupt the code around them.
The full cheatsheet, including the ordering semantics and the caching argument, is here.
Check your own project. The scan is free, runs entirely on your machine, and reports this rule with the exact assets that trip it — nothing is uploaded.
Last reviewed · All rules