EllanJiang/GameFramework · error · GameFrameworkException

Name is invalid.

Error message

Name is invalid.

What it means

DataNode.HasChild throws 'Name is invalid.' when the child name argument fails IsValidName (null/empty/illegal characters). HasChild is a boolean existence check, so rather than returning false it demands a well-formed name. This prevents silent 'child not found' results caused by malformed input.

Solutions

  1. Pass a single valid child name, not a full path — use GetNode for paths
  2. Validate with DataNode.IsValidName(name) before calling
  3. Trim/normalize the name and reject empty segments

Example fix

// before
bool has = node.HasChild(childName);
// after
if (DataNode.IsValidName(childName))
{
    bool has = node.HasChild(childName);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!DataNode.IsValidName(name))
{
    return false;
}

Type guard

bool ValidChildName(string s) => !string.IsNullOrEmpty(s) && !s.Contains("/");

Try / catch

try { has = node.HasChild(name); }
catch (GameFrameworkException) { Log.Error($"Invalid child name '{name}'"); has = false; }

Prevention

When it happens

Trigger: Calling node.HasChild(null), HasChild(""), or HasChild("a/b") — a name containing the path separator; passing a variable that was split from a path into an empty segment.

Common situations: Querying children with a full path instead of a single child name (paths belong to GetNode); an uninitialized string variable; empty entries from a Split('/') producing empty segments.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/DataNode/DataNodeManager.DataNode.cs:159

            /// 根据索引检查是否存在子数据结点。
            /// </summary>
            /// <param name="index">子数据结点的索引。</param>
            /// <returns>是否存在子数据结点。</returns>
            public bool HasChild(int index)
            {
                return index >= 0 && index < ChildCount;
            }

            /// <summary>
            /// 根据名称检查是否存在子数据结点。
            /// </summary>
            /// <param name="name">子数据结点名称。</param>
            /// <returns>是否存在子数据结点。</returns>
            public bool HasChild(string name)
            {
                if (!IsValidName(name))
                {
                    throw new GameFrameworkException("Name is invalid.");
                }

                if (m_Childs == null)
                {
                    return false;
                }

                foreach (DataNode child in m_Childs)
                {
                    if (child.Name == name)
                    {
                        return true;
                    }
                }

                return false;
            }

View on GitHub (pinned to d0c010b051)