Unity-Technologies/UnityCsReference · error · KeyNotFoundException

EntityId was not found:

Error message

EntityId was not found: 

What it means

ProjectBrowserColumnOne.GetIdFor throws a KeyNotFoundException when the requested EntityId has no mapping in the internal lookup. This is an internal editor method for the Project Browser's virtualized list view that maps EntityIds to internal integer IDs for rendering.

Source

Thrown at Editor/Mono/ProjectBrowser/ProjectBrowserColumnOne.cs:624

                {
                    CacheMapping(id, pair.entityId);
                    return pair.entityId;
                }
            }

            // Allocate new EntityId
            var newEntityId = EntityId.AllocateEntityId();
            m_AllocatedEntityIds.Add(new IdPair(id, newEntityId));
            CacheMapping(id, newEntityId);
            return newEntityId;
        }

        public int GetIdFor(EntityId entityId)
        {
            if (TryGetIdFor(entityId, out int id))
                return id;

            throw new KeyNotFoundException("EntityId was not found: " + entityId);
        }

        public bool TryGetIdFor(EntityId entityId, out int id)
        {
            if (m_LookupId.TryGetValue(entityId, out int intId))
            {
                id = intId;
                return true;
            }

            // Fallback to list traversal (should only happen once per id, at startup and after domain reloading)
            foreach (var pair in m_AllocatedEntityIds)
            {
                if (pair.entityId == entityId)
                {
                    CacheMapping(pair.id, entityId);
                    id = pair.id;
                    return true;

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. This is an internal API; restart the editor or force a Project Browser repaint/reload if hit.
  2. Use TryGetIdFor (the non-throwing variant) if you have internal access and need to guard.
  3. Avoid manipulating EntityId mappings from custom editor code; they are managed by the Project Browser internally.

Example fix

// before
int id = browser.GetIdFor(entityId);
// after (if internal access available)
if (browser.TryGetIdFor(entityId, out int id))
{ /* use id */ }
else
    Debug.LogWarning("EntityId not found, likely stale after domain reload");
Defensive patterns

Strategy: validation

Validate before calling

// Internal API — use TryGetIdFor instead of GetIdFor
if (browser.TryGetIdFor(entityId, out int id))
{ /* use id */ }
else
    Debug.LogWarning("EntityId not mapped");

Prevention

When it happens

Trigger: Calling GetIdFor with an EntityId that was never allocated through AllocateEntityId (internal) or was allocated in a previous session and lost after a domain reload.

Common situations: This is an internal Unity editor API not intended for direct use. Errors here typically come from bugs in Unity's own Project Browser code after a domain reload or asset import where EntityId mappings become stale. Custom editor extensions that manipulate project browser internals may also trigger it.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/8211dc613efc4b94. Report an issue: GitHub.