{"record":{"id":"5ae1b92c09f0ad97","repo":"EllanJiang/GameFramework","slug":"entity-asset-name-is-invalid-entitymanager","errorCode":null,"errorMessage":"Entity asset name is invalid.","messagePattern":"Entity asset name is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Entity/EntityManager.cs","lineNumber":368,"sourceCode":"        /// 是否存在实体。\n        /// </summary>\n        /// <param name=\"entityId\">实体编号。</param>\n        /// <returns>是否存在实体。</returns>\n        public bool HasEntity(int entityId)\n        {\n            return m_EntityInfos.ContainsKey(entityId);\n        }\n\n        /// <summary>\n        /// 是否存在实体。\n        /// </summary>\n        /// <param name=\"entityAssetName\">实体资源名称。</param>\n        /// <returns>是否存在实体。</returns>\n        public bool HasEntity(string entityAssetName)\n        {\n            if (string.IsNullOrEmpty(entityAssetName))\n            {\n                throw new GameFrameworkException(\"Entity asset name is invalid.\");\n            }\n\n            foreach (KeyValuePair<int, EntityInfo> entityInfo in m_EntityInfos)\n            {\n                if (entityInfo.Value.Entity.EntityAssetName == entityAssetName)\n                {\n                    return true;\n                }\n            }\n\n            return false;\n        }\n\n        /// <summary>\n        /// 获取实体。\n        /// </summary>\n        /// <param name=\"entityId\">实体编号。</param>\n        /// <returns>要获取的实体。</returns>","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Entity/EntityManager.cs#L350-L386","documentation":"GameFramework's EntityManager.HasEntity throws this when the entityAssetName argument is null or an empty string. The library treats the entity asset name as a required identifier, so it fails fast rather than returning a misleading result. The check is a simple string.IsNullOrEmpty guard at the top of the method.","triggerScenarios":"Calling HasEntity(entityAssetName) with a null or \"\" string, e.g. a variable that failed to initialize or an empty config/inspector field.","commonSituations":"Entity asset name read from configuration or a Unity inspector field left blank; a lookup dictionary returning null; building the name by string concatenation where one part is empty.","solutions":["Pass a valid, non-empty entity asset name such as the asset path used when the entity was shown.","Guard the caller: check string.IsNullOrEmpty(entityAssetName) before calling HasEntity and skip or substitute a default name.","Fix the source of the empty string (config file, inspector field, or path-building code)."],"exampleFix":"// before\nbool exists = entityManager.HasEntity(entityAssetName);\n// after\nbool exists = !string.IsNullOrEmpty(entityAssetName) && entityManager.HasEntity(entityAssetName);","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrEmpty(entityAssetName))\n{\n    bool exists = entityManager.HasEntity(entityAssetName);\n}","typeGuard":"bool IsValidEntityAssetName(string name) => !string.IsNullOrEmpty(name);","tryCatchPattern":"try { return entityManager.HasEntity(name); }\ncatch (GameFrameworkException) { return false; }","preventionTips":["Centralize entity name construction in one utility (e.g. AssetUtility.GetEntityAsset) so it can never return null/empty silently.","Validate config/inspector entity name fields at load time and fail early.","Never pass serialized strings straight into EntityManager without a null/empty check."],"tags":["gameframework","entity","argument-validation","null-check"],"backgroundTag":"empty-required-field","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"}