EllanJiang/GameFramework · error · GameFrameworkException
State type is invalid.
Error message
State type is invalid.
What it means
Guard in Fsm<T>.Start(Type): thrown when stateType is null. Starting the state machine requires an initial state type to look up among the registered states; a null type cannot be resolved, so the FSM refuses to start rather than entering an invalid state.
Solutions
- Ensure the Type value is resolved (typeof(TState) or Type.GetType with a valid assembly-qualified name) before calling Start
- Use the generic Start<TState>() overload, which cannot receive null
- Validate the field/config value at load time and fail early
Example fix
// before Type startState = Type.GetType(stateTypeName); fsm.Start(startState); // null if name wrong // after Type startState = Type.GetType(stateTypeName) ?? typeof(IdleState); if (startState != null) fsm.Start(startState);
Defensive patterns
Strategy: validation
Validate before calling
if (stateType == null)
throw new ArgumentException("Start state type must be resolved before calling Start");
fsm.Start(stateType); Type guard
bool IsValidStateType(Type t) => t != null && typeof(FsmState<T>).IsAssignableFrom(t);
Try / catch
try { fsm.Start(stateType); }
catch (GameFrameworkException ex) { Log.Error("Invalid start state type: {0}", ex.Message); } Prevention
- Prefer the generic Start<TState>() overload
- Validate serialized/config type names at load time
- Use assembly-qualified names with Type.GetType and log resolution failures
When it happens
Trigger: Calling fsm.Start(someType) where someType is null, typically from a Type variable filled by typeof on a null source, reflection that failed to resolve the type, or serialized/type-reference data that was never assigned.
Common situations: Config-driven FSM startup where the initial state type string failed to resolve to a Type; ScriptableObject/Inspector fields of System.Type left unset; reflection by name with a typo or a type stripped by IL2CPP.
Related errors
- Results is invalid.
- Task agent is invalid.
- Results is invalid.
- Download agent helper is invalid.
- Task is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/577fd9c753246af9.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Fsm/Fsm.cs:287
m_CurrentStateTime = 0f;
m_CurrentState = state;
m_CurrentState.OnEnter(this);
}
/// <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);
}
View on GitHub (pinned to d0c010b051)