EllanJiang/GameFramework · error · GameFrameworkException

Entity asset name is invalid.

Error message

Entity asset name is invalid.

What it means

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.

Solutions

  1. Pass a valid, non-empty entity asset name such as the asset path used when the entity was shown.
  2. Guard the caller: check string.IsNullOrEmpty(entityAssetName) before calling HasEntity and skip or substitute a default name.
  3. Fix the source of the empty string (config file, inspector field, or path-building code).

Example fix

// before
bool exists = entityManager.HasEntity(entityAssetName);
// after
bool exists = !string.IsNullOrEmpty(entityAssetName) && entityManager.HasEntity(entityAssetName);
Defensive patterns

Strategy: validation

Validate before calling

if (!string.IsNullOrEmpty(entityAssetName))
{
    bool exists = entityManager.HasEntity(entityAssetName);
}

Type guard

bool IsValidEntityAssetName(string name) => !string.IsNullOrEmpty(name);

Try / catch

try { return entityManager.HasEntity(name); }
catch (GameFrameworkException) { return false; }

Prevention

When it happens

Trigger: Calling HasEntity(entityAssetName) with a null or "" string, e.g. a variable that failed to initialize or an empty config/inspector field.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/5ae1b92c09f0ad97. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Entity/EntityManager.cs:368

        /// 是否存在实体。
        /// </summary>
        /// <param name="entityId">实体编号。</param>
        /// <returns>是否存在实体。</returns>
        public bool HasEntity(int entityId)
        {
            return m_EntityInfos.ContainsKey(entityId);
        }

        /// <summary>
        /// 是否存在实体。
        /// </summary>
        /// <param name="entityAssetName">实体资源名称。</param>
        /// <returns>是否存在实体。</returns>
        public bool HasEntity(string entityAssetName)
        {
            if (string.IsNullOrEmpty(entityAssetName))
            {
                throw new GameFrameworkException("Entity asset name is invalid.");
            }

            foreach (KeyValuePair<int, EntityInfo> entityInfo in m_EntityInfos)
            {
                if (entityInfo.Value.Entity.EntityAssetName == entityAssetName)
                {
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// 获取实体。
        /// </summary>
        /// <param name="entityId">实体编号。</param>
        /// <returns>要获取的实体。</returns>

View on GitHub (pinned to d0c010b051)