EllanJiang/GameFramework · error · GameFrameworkException
FSM ' ' can not change state to ' ' which is not exist.
Error message
FSM '{0}' can not change state to '{1}' which is not exist. What it means
After confirming a current state, ChangeState(Type) resolves the target via GetState(stateType). If no state of that type is registered in this FSM, it throws GameFrameworkException with "FSM '{0}' can not change state to '{1}' which is not exist.", naming the FSM (TypeNamePair of state type + name) and the missing type's full name.
Solutions
- Add the target state type to the states array in the Fsm.Create call
- Correct the ChangeState type argument to a registered state type
- Audit all transitions after removing/renaming state classes
- Guard with HasState-style checks or wrap transitions in try-catch during development
Example fix
// before Fsm<T> fsm = Fsm<T>.Create(name, owner); // no states registered fsm.ChangeState(typeof(IdleState)); // throws // after Fsm<T> fsm = Fsm<T>.Create(name, owner, new IdleState(), new MoveState()); fsm.ChangeState(typeof(IdleState)); // OK
Defensive patterns
Strategy: validation
Validate before calling
if (fsm.GetState(typeof(TargetState)) == null) throw new InvalidOperationException("Target state not registered in this FSM"); Try / catch
try { fsm.ChangeState(typeof(TargetState)); } catch (GameFrameworkException ex) when (ex.Message.Contains("can not change state to")) { /* fall back to a default state or log missing registration */ } Prevention
- Register every state referenced by transitions in the CreateFsm states array
- Audit transitions after renaming or removing state classes
- Keep state registration and transition tables in one place for review
When it happens
Trigger: Calling fsm.ChangeState(typeof(SomeState)) where SomeState was never included in the states array passed at Fsm creation; typos in the generic type argument; a state registered on a different FSM instance.
Common situations: Adding a new state class but forgetting to add it to the CreateFsm states list; copy-pasted ChangeState calls referencing states from another FSM; refactoring that removed a state while leaving transitions pointing at it.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Current state is invalid.
- FSM is invalid.
- State type is invalid.
- State type ' ' is invalid.
- FSM owner is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/32b8dc94e12cf549.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Fsm/Fsm.cs:579
{
ChangeState(typeof(TState));
}
/// <summary>
/// 切换当前有限状态机状态。
/// </summary>
/// <param name="stateType">要切换到的有限状态机状态类型。</param>
internal void ChangeState(Type stateType)
{
if (m_CurrentState == null)
{
throw new GameFrameworkException("Current state is invalid.");
}
FsmState<T> state = GetState(stateType);
if (state == null)
{
throw new GameFrameworkException(Utility.Text.Format("FSM '{0}' can not change state to '{1}' which is not exist.", new TypeNamePair(typeof(T), Name), stateType.FullName));
}
m_CurrentState.OnLeave(this, false);
m_CurrentStateTime = 0f;
m_CurrentState = state;
m_CurrentState.OnEnter(this);
}
}
}
View on GitHub (pinned to d0c010b051)