{"record":{"id":"96b1f56205cc201b","repo":"EllanJiang/GameFramework","slug":"entity-0-is-already-being-loaded","errorCode":null,"errorMessage":"Entity '{0}' is already being loaded.","messagePattern":"Entity '(.+?)' is already being loaded\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Entity/EntityManager.cs","lineNumber":637,"sourceCode":"\n            if (string.IsNullOrEmpty(entityAssetName))\n            {\n                throw new GameFrameworkException(\"Entity asset name is invalid.\");\n            }\n\n            if (string.IsNullOrEmpty(entityGroupName))\n            {\n                throw new GameFrameworkException(\"Entity group name is invalid.\");\n            }\n\n            if (HasEntity(entityId))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Entity id '{0}' is already exist.\", entityId));\n            }\n\n            if (IsLoadingEntity(entityId))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Entity '{0}' is already being loaded.\", entityId));\n            }\n\n            EntityGroup entityGroup = (EntityGroup)GetEntityGroup(entityGroupName);\n            if (entityGroup == null)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Entity group '{0}' is not exist.\", entityGroupName));\n            }\n\n            EntityInstanceObject entityInstanceObject = entityGroup.SpawnEntityInstanceObject(entityAssetName);\n            if (entityInstanceObject == null)\n            {\n                int serialId = ++m_Serial;\n                m_EntitiesBeingLoaded.Add(entityId, serialId);\n                m_ResourceManager.LoadAsset(entityAssetName, priority, m_LoadAssetCallbacks, ShowEntityInfo.Create(serialId, entityId, entityGroup, userData));\n                return;\n            }\n\n            InternalShowEntity(entityId, entityAssetName, entityGroup, entityInstanceObject.Target, false, 0f, userData);","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Entity/EntityManager.cs#L619-L655","documentation":"EntityManager tracks entities currently being asynchronously loaded. If ShowEntity is called with an entityId whose asset load is still in flight, IsLoadingEntity returns true and this exception is thrown, preventing a double load for the same id.","triggerScenarios":"Calling ShowEntity again with an entityId whose previous ShowEntity call has not yet completed its asset load (LoadAsset success callback not yet fired).","commonSituations":"User clicks a spawn button twice before the async load finishes; retry logic re-issuing ShowEntity on a slow load; UI event fired multiple times while a prefab loads from disk or network.","solutions":["Guard with IsLoadingEntity(entityId) before calling ShowEntity again","Debounce/duplicate-suppress the UI event that triggers ShowEntity","Queue the second request and apply it in the ShowEntitySuccess callback instead of re-calling"],"exampleFix":"// before\nm_EntityComponent.ShowEntity(id, \"Player\", \"PlayerGroup\", null); // may double-fire\n// after\nif (!m_EntityComponent.IsLoadingEntity(id) && !m_EntityComponent.HasEntity(id))\n{\n    m_EntityComponent.ShowEntity(id, \"Player\", \"PlayerGroup\", null);\n}","handlingStrategy":"validation","validationCode":"if (entityManager.IsLoadingEntity(entityId) || entityManager.HasEntity(entityId)) return;","typeGuard":"bool IsLoadable(int id) => !entityManager.IsLoadingEntity(id);","tryCatchPattern":"try { ShowEntity(id, asset, group, userData); } catch (GameFrameworkException ex) when (ex.Message.Contains(\"already being loaded\")) { Debug.LogWarning($\"Entity {id} load in progress\"); }","preventionTips":["Debounce UI triggers that spawn entities","Track pending load ids in your own set","Reissue requests from ShowEntitySuccess callbacks, not timers"],"tags":["unity","gameframework","entity","async"],"backgroundTag":"invalid-state-transition","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}