EllanJiang/GameFramework · error · GameFrameworkException
State type ' ' is invalid.
Error message
State type '{0}' is invalid. What it means
Fsm.Start(Type) throws this when the given type does not derive from FsmState<T>, the required state base class for this FSM's owner type. Start only accepts valid state types of the matching owner type.
Solutions
- Make the state class derive from FsmState<T> with the same owner type T as the FSM
- Use the strongly typed Start<TState>() overload so the compiler enforces the base class
- Fix the owner type T used in Fsm.Create/AddFsm if states were written for a different owner
Example fix
// before
fsm.Start(typeof(SomeClass)); // not an FsmState<T>
// after
public class SomeClass : FsmState<FsmOwner> { }
fsm.Start(typeof(SomeClass)); Defensive patterns
Strategy: type-guard
Validate before calling
if (stateType == null || !typeof(FsmState<T>).IsAssignableFrom(stateType))
throw new ArgumentException("Type must derive from FsmState<T>");
fsm.Start(stateType); Type guard
bool IsStateOfType<TOwner>(Type t) => t != null && typeof(FsmState<TOwner>).IsAssignableFrom(t);
Try / catch
try { fsm.Start(stateType); }
catch (GameFrameworkException ex) { Log.Error("State type {0} is not a valid FsmState<T>", stateType?.FullName); } Prevention
- Derive every state from FsmState<T> with the FSM's owner type
- Use generic Start<TState>() so the compiler enforces the base class
- Avoid sharing state classes across FSMs with different owner types
When it happens
Trigger: Passing a Type that is not a subclass of FsmState<T> to Start(Type), e.g. a state registered for a different owner type FsmState<OtherOwner>, an unrelated class, or an interface.
Common situations: Mixing states from two FSMs with different owner types; using the wrong T generic parameter when creating the FSM; config-driven startup resolving a type name that points at the wrong class after a refactor.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- FSM ' ' can not start state ' ' which is not exist.
- State type is invalid.
- Results is invalid.
- State type is invalid.
- State type ' ' is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/30e6fa797fb53a95.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Fsm/Fsm.cs:292
/// <summary>
/// 开始有限状态机。
/// </summary>
/// <param name="stateType">要开始的有限状态机状态类型。</param>
public void Start(Type stateType)
{
if (IsRunning)
{
throw new GameFrameworkException("FSM is running, can not start again.");
}
if (stateType == null)
{
throw new GameFrameworkException("State type is invalid.");
}
if (!typeof(FsmState<T>).IsAssignableFrom(stateType))
{
throw new GameFrameworkException(Utility.Text.Format("State type '{0}' is invalid.", stateType.FullName));
}
FsmState<T> state = GetState(stateType);
if (state == null)
{
throw new GameFrameworkException(Utility.Text.Format("FSM '{0}' can not start state '{1}' which is not exist.", new TypeNamePair(typeof(T), Name), stateType.FullName));
}
m_CurrentStateTime = 0f;
m_CurrentState = state;
m_CurrentState.OnEnter(this);
}
/// <summary>
/// 是否存在有限状态机状态。
/// </summary>
/// <typeparam name="TState">要检查的有限状态机状态类型。</typeparam>
/// <returns>是否存在有限状态机状态。</returns>View on GitHub (pinned to d0c010b051)