Skip to content
CW
Navigation

Language

Navigation

Back to Blog
14 Aug 2026 Updated 15 Aug 2026 7 min read 17 Views
Unity 6000.5 Breaking Change: Migrating InstanceID to EntityId

Unity 6000.5 Breaking Change: Migrating InstanceID to EntityId

Unity 6000.5 replaces int instanceID with the new EntityId struct across the entire API. Here's every rename, semantic gotcha, and fix needed to compile clean.

Introduction

Every major Unity upgrade comes with a familiar ritual: you hit Upgrade, wait for the reimport, and then watch the Console fill up with red CS0619 errors. Upgrading a real production project to Unity 6000.5.7f1 was no exception β€” but this time, almost every error traced back to the same root cause: Unity quietly replaced int instanceID with a brand-new struct called EntityId across a huge chunk of its public API.

This isn't a one-off obsolete method here or there. It's an engine-wide type change that touches GameObject, Object, EditorUtility, EditorApplication, and any of your own code that stored or compared instance IDs. If you maintain a project with third-party assets or your own Editor tooling, this is the change that will cost you the most time β€” so this post focuses entirely on it.

All the fixes below are 1:1 replacements. Nothing here changes your game's behavior β€” it just moves your code onto the current, non-obsolete API surface.

The Problem: int instanceID Is Being Replaced by EntityId

Historically, every UnityEngine.Object exposed GetInstanceID(), returning a plain int that uniquely identified the object for that session. Unity 6000.5 introduces EntityId, a lightweight struct that replaces int as the canonical identifier type across the Editor and runtime APIs. The old int-based members still exist for now, but they're marked obsolete and β€” in this project's case β€” configured to raise a hard CS0619 error, not just a warning:

error CS0619: 'EditorApplication.hierarchyWindowItemOnGUI' is obsolete:
'Use hierarchyWindowItemByEntityIdOnGUI instead. (UnityUpgradable)'

Once one script uses the old API, the whole project fails to compile β€” including Play Mode. Here's the full set of renames I had to apply.

Fix 1: GetInstanceID() β†’ GetEntityId()

The most common change. Any code that grabbed a numeric ID for a GameObject, Material, or other Object needs to switch to the new accessor:

// Before
int uniqueId = sourceObject.GetInstanceID();

// After
EntityId uniqueId = sourceObject.GetEntityId();

This also means every Dictionary<int, T> or Dictionary<int, List<T>> keyed by instance ID needs its key type updated:

// Before
private Dictionary<int, List<GameObject>> instantiatedObjects = new Dictionary<int, List<GameObject>>();
private Dictionary<int, int> poolCursors = new Dictionary<int, int>();

// After
private Dictionary<EntityId, List<GameObject>> instantiatedObjects = new Dictionary<EntityId, List<GameObject>>();
private Dictionary<EntityId, int> poolCursors = new Dictionary<EntityId, int>();

EntityId implements equality and hashing correctly, so it drops into a Dictionary key exactly like int did β€” no behavior change, just a type swap.

Fix 2: EditorUtility.InstanceIDToObject β†’ EntityIdToObject

Editor tooling that resolves an object back from its ID needs the matching lookup method:

// Before
GameObject gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;

// After
GameObject gameObject = EditorUtility.EntityIdToObject(entityId) as GameObject;

Fix 3: Hierarchy Window Callbacks

If you draw custom icons or overlays in the Hierarchy window, the delegate type and the event itself were renamed:

// Before
private static readonly EditorApplication.HierarchyWindowItemCallback callback;

static MyTool()
{
    callback = new EditorApplication.HierarchyWindowItemCallback(DrawIcon);
    EditorApplication.hierarchyWindowItemOnGUI =
        (EditorApplication.HierarchyWindowItemCallback)Delegate.Combine(
            EditorApplication.hierarchyWindowItemOnGUI, callback);
}

private static void DrawIcon(int instanceID, Rect selectionRect) { /* ... */ }
// After
private static readonly EditorApplication.HierarchyWindowItemByEntityIdCallback callback;

static MyTool()
{
    callback = new EditorApplication.HierarchyWindowItemByEntityIdCallback(DrawIcon);
    EditorApplication.hierarchyWindowItemByEntityIdOnGUI =
        (EditorApplication.HierarchyWindowItemByEntityIdCallback)Delegate.Combine(
            EditorApplication.hierarchyWindowItemByEntityIdOnGUI, callback);
}

private static void DrawIcon(EntityId entityId, Rect selectionRect) { /* ... */ }

Same pattern for subscribing/unsubscribing with += / -= elsewhere in your Editor code β€” just swap hierarchyWindowItemOnGUI for hierarchyWindowItemByEntityIdOnGUI.

Fix 4: The Semantic Trap β€” EntityId Has No Negative Values

This is the gotcha that won't show up as a compile error, only as a silent behavior bug. A lot of older Unity code used a simple convention: negative instance IDs mean the object exists only in memory (created at runtime, not saved as an asset), while positive IDs mean a persistent asset. Code relied on this to decide things like "should I duplicate this material" or "is this a scene instance vs. a prefab asset":

// Before – relies on int sign
instanceID = GetInstanceID();
if (instanceID < 0)
{
    DuplicateMaskedMaterials();
}

EntityId doesn't carry that sign convention β€” all its values behave as unsigned identifiers, so < 0 comparisons stop being meaningful. The correct replacement is to ask the Editor directly whether the object is a persistent asset:

// After – explicit intent instead of relying on ID sign
instanceID = GetEntityId();
if (!EditorUtility.IsPersistent(this))
{
    DuplicateMaskedMaterials();
}

Also watch for the "not yet initialized" check. Code used to compare against 0:

// Before
if (instanceID == 0) { instanceID = GetInstanceID(); }

// After
if (!instanceID.IsValid()) { instanceID = GetEntityId(); }

πŸ›‘ Why this matters more than the renames

A rename that doesn't compile is a five-minute fix. A sign-based check that silently stops working is a bug that only shows up later β€” for example, materials failing to duplicate correctly for runtime-created objects. If your project has any `instanceID < 0` or `instanceID > 0` logic, audit it specifically; don't assume a simple find-and-replace of the method name is enough.

Fix 5: Serialized int instanceID Fields

If a MonoBehaviour serializes an instance ID to detect duplication (a common trick for "has this object been cloned since I last checked" logic), the field type itself needs to change:

// Before
[SerializeField]
int instanceID = 0;

// After
[SerializeField]
EntityId instanceID;

EntityId is a serializable struct, so this is a drop-in field type change β€” Unity handles the serialization for you.

A Broader Pattern: Obsolete-as-Error Is the New Normal

Beyond EntityId, this upgrade also flagged other engine APIs that were previously "soft obsolete" (a CS0618 warning) and are now hard errors under Unity 6000.5's analyzer settings β€” for example, HierarchyProperty (replaced by HierarchyIterator, or by SceneManager.GetRootGameObjects() for the common "enumerate scene roots" case) and MaterialProperty.type (replaced by MaterialProperty.propertyType returning ShaderPropertyType). The lesson generalizes: treat every CS0619 as a hard blocker, not something to silence with a pragma, because Unity is visibly trending toward making obsolete APIs non-negotiable rather than just discouraged.

A Practical Checklist for the EntityId Migration

  1. Search your project for GetInstanceID(), InstanceIDToObject, hierarchyWindowItemOnGUI, and Dictionary<int, β€” these are the highest-hit-rate patterns.
  2. For every serialized int that stores an instance ID, switch the field type to EntityId.
  3. Audit any < 0 / > 0 / == 0 comparison on an old instance ID β€” these encode assumptions that don't hold for EntityId and need IsValid() / EditorUtility.IsPersistent() instead.
  4. Update Dictionary/HashSet key types from int to EntityId wherever they were keyed by instance ID.
  5. Rebuild (not just Play Mode) once the Console is clean β€” some of these paths only execute during a build or in batch mode.

Conclusion

Unity 6000.5's EntityId migration is the kind of change that looks like a simple rename until you hit the sign-comparison gotcha β€” and that's the part worth remembering, not just the syntax. GetInstanceID() β†’ GetEntityId(), InstanceIDToObject β†’ EntityIdToObject, hierarchyWindowItemOnGUI β†’ hierarchyWindowItemByEntityIdOnGUI, and id < 0 β†’ !EditorUtility.IsPersistent(this) were enough to get a real production project compiling and behaving correctly again on Unity 6000.5.7f1.

If you're hitting a specific EntityId-related error that isn't covered here, drop a comment or reach out β€” happy to help track down the fix.

FAQ

Why does my Unity project fail to compile after upgrading to Unity 6000.5 with a CS0619 error mentioning EntityId?

Unity 6000.5 replaced the old int-based GetInstanceID API with a new EntityId struct across the Editor and runtime APIs. Any code still calling the obsolete int-based members now raises a hard CS0619 compile error instead of a warning, and a single failing script blocks the entire project from compiling, including Play Mode.

What replaces GetInstanceID() in Unity 6000.5?

Use GetEntityId(), which returns the new EntityId struct instead of a plain int. Any Dictionary or HashSet previously keyed by int should have its key type updated to EntityId as well, since EntityId implements equality and hashing the same way.

Why does my code that checks "if (instanceID < 0)" stop working correctly after switching to EntityId?

EntityId does not use the old sign convention where a negative value meant a runtime-only object. Replace sign-based checks with EditorUtility.IsPersistent(this) to determine whether an object is a saved asset instead of relying on the identifier's sign.

Is HierarchyProperty also removed in Unity 6000.5?

HierarchyProperty is marked obsolete and, under this project's analyzer settings, raises a compile error too. Use HierarchyIterator, or SceneManager.GetRootGameObjects() for the common case of enumerating root objects across loaded scenes.

Do I need to manually patch every third-party asset for Unity 6000.5?

Check the Asset Store or Package Manager for an updated version first, since most plugin authors ship Unity 6-compatible releases quickly. Only patch the source directly, following the EntityId renames in this guide, when no updated version is available yet.

Cezar Wagenheimer

Written by

Cezar Wagenheimer

Share this article

Comments

Have a question, or found an issue with the code? Drop a comment below — I read and reply to every one.

Loading comments…

Leave a comment

Keep exploring