FindObjectsOfType is obsolete: use FindObjectsByType

Object.FindObjectsOfType is obsolete in Unity 6. The right FindObjectsByType call depends on your version: with a sort mode up to 6.4, without one from 6.5.

Status
Obsolete since Unity 6.0 · Scripting
Old
Object.FindObjectsOfType
New
Object.FindObjectsByType
Checked
2026-10-05, against the sources below

What changed

Object.FindObjectsOfType is obsolete in Unity 6.0. Its replacement, FindObjectsByType, changed again in Unity 6.5, so the correct fix depends on the version you target.

From 6.0 to 6.4, FindObjectsByType requires a FindObjectsSortMode. FindObjectsOfType always sorted by InstanceID; FindObjectsSortMode.None skips the sort and is considerably faster when the order does not matter.

From 6.5, every overload that takes a FindObjectsSortMode is itself deprecated, because InstanceID is being replaced by EntityId and the old order cannot be kept. Call FindObjectsByType<T>() or FindObjectsByType<T>(FindObjectsInactive) with no sort mode.

Before and after

Before
C#
Enemy[] enemies = FindObjectsOfType<Enemy>();
After
C#
// Unity 6.0 to 6.4
Enemy[] enemies = FindObjectsByType<Enemy>(FindObjectsSortMode.None);

// Unity 6.5 and newer
Enemy[] enemies = FindObjectsByType<Enemy>();

Fix it automatically

Paste a script into the Unity 6 Script Upgrade Checker and it applies this rename for you, along with the other safe fixes for your target version.

Open this example in the checker

Questions

How do I write code that compiles on 6.0 and on 6.5 without warnings?
Branch on the version define: #if UNITY_6000_5_OR_NEWER call FindObjectsByType<Enemy>(), #else call FindObjectsByType<Enemy>(FindObjectsSortMode.None). Unity defines a UNITY_X_Y_OR_NEWER symbol for each release.
Does FindObjectsByType include inactive objects?
Not by default. Pass FindObjectsInactive.Include to find disabled objects as well, which is what the old FindObjectsOfType(true) did.

Sources

Related Unity 6 changes

Every Unity 6.x change, by version