EllanJiang/GameFramework · error · GameFrameworkException

UI group name is invalid.

Error message

UI group name is invalid.

What it means

HasUIGroup looks up a UI group by name in the UIManager's dictionary; an empty or null name can never match a group, so it is rejected with an explicit GameFrameworkException instead of returning false. This fail-fast distinguishes 'you passed a bad argument' from 'the group does not exist', since returning false for an invalid name would mask caller bugs.

Solutions

  1. Pass a non-empty UI group name that was previously added via AddUIGroup
  2. Guard the caller: if (string.IsNullOrEmpty(name)) return; before calling HasUIGroup
  3. Fix the source of the empty name (config file, prefab inspector field, or constructor default)
  4. Use TryGetValue-style patterns via GetUIGroup only after validating the name

Example fix

// before
bool exists = ui.HasUIGroup(groupName); // groupName may be ""
// after
if (!string.IsNullOrEmpty(groupName))
{
    bool exists = ui.HasUIGroup(groupName);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!string.IsNullOrEmpty(uiGroupName))
    exists = uiManager.HasUIGroup(uiGroupName);

Type guard

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

Try / catch

try { return uiManager.HasUIGroup(name); }
catch (GameFrameworkException) { return false; }

Prevention

When it happens

Trigger: Calling HasUIGroup(null) or HasUIGroup("") — commonly when a group name variable was never set, or a UIForm instance carries an empty group name from bad configuration.

Common situations: UI form prefabs serialized with an empty group name field; config-driven UI layouts where the group name column is blank; string concatenation producing an empty name.

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/1f6284d821970505. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/UI/UIManager.cs:291

        {
            if (uiFormHelper == null)
            {
                throw new GameFrameworkException("UI form helper is invalid.");
            }

            m_UIFormHelper = uiFormHelper;
        }

        /// <summary>
        /// 是否存在界面组。
        /// </summary>
        /// <param name="uiGroupName">界面组名称。</param>
        /// <returns>是否存在界面组。</returns>
        public bool HasUIGroup(string uiGroupName)
        {
            if (string.IsNullOrEmpty(uiGroupName))
            {
                throw new GameFrameworkException("UI group name is invalid.");
            }

            return m_UIGroups.ContainsKey(uiGroupName);
        }

        /// <summary>
        /// 获取界面组。
        /// </summary>
        /// <param name="uiGroupName">界面组名称。</param>
        /// <returns>要获取的界面组。</returns>
        public IUIGroup GetUIGroup(string uiGroupName)
        {
            if (string.IsNullOrEmpty(uiGroupName))
            {
                throw new GameFrameworkException("UI group name is invalid.");
            }

            UIGroup uiGroup = null;

View on GitHub (pinned to d0c010b051)