EllanJiang/GameFramework · error · GameFrameworkException

UI form is invalid.

Error message

UI form is invalid.

What it means

GetUIFormInfo is the private lookup used by RemoveUIForm/RefocusUIForm. It throws GameFrameworkException('UI form is invalid.') when the uiForm parameter itself is null, before any list search, because a null form can never match a tracked instance.

Solutions

  1. Null-check the IUIForm reference before CloseUIForm/RefocusUIForm
  2. Fix the lookup/assignment that produced the null reference
  3. Wait for the async OpenUIForm callback before closing or refocusing the form

Example fix

// before
uiGroup.CloseUIForm(m_Form); // m_Form may be null
// after
if (m_Form != null)
{
    uiGroup.CloseUIForm(m_Form);
    m_Form = null;
}
Defensive patterns

Strategy: validation

Validate before calling

if (uiForm == null) return;

Type guard

bool IsValidForm(IUIForm form) => form != null;

Try / catch

try { uiGroup.CloseUIForm(uiForm); } catch (GameFrameworkException ex) when (ex.Message == "UI form is invalid.") { Log.Warn("Attempted to close a null UI form"); }

Prevention

When it happens

Trigger: Calling RemoveUIForm(null) or RefocusUIForm(null) — i.e. CloseUIForm or RefocusUIForm propagated a null form reference.

Common situations: CloseUIForm fed by a dictionary lookup that missed; a nullable form field never assigned; async open flows where the form reference is captured before it is available.

Related errors


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

Appendix: source

Thrown at GameFramework/UI/UIManager.UIGroup.cs:502

                    {
                        results.Add(uiFormInfo.UIForm);
                    }
                }
            }

            internal void InternalGetAllUIForms(List<IUIForm> results)
            {
                foreach (UIFormInfo uiFormInfo in m_UIFormInfos)
                {
                    results.Add(uiFormInfo.UIForm);
                }
            }

            private UIFormInfo GetUIFormInfo(IUIForm uiForm)
            {
                if (uiForm == null)
                {
                    throw new GameFrameworkException("UI form is invalid.");
                }

                foreach (UIFormInfo uiFormInfo in m_UIFormInfos)
                {
                    if (uiFormInfo.UIForm == uiForm)
                    {
                        return uiFormInfo;
                    }
                }

                return null;
            }
        }
    }
}

View on GitHub (pinned to d0c010b051)