EllanJiang/GameFramework · error · GameFrameworkException

FSM ' ' can not start state ' ' which is not exist.

Error message

FSM '{0}' can not start state '{1}' which is not exist.

What it means

Fsm.Start<TState>() throws when the requested state type was never registered on this FSM instance. The FSM looks up the state by type via GetState<TState>() and throws a GameFrameworkException when the lookup returns null, so it refuses to enter a state it does not own.

Solutions

  1. Add the state type to the states array passed to Fsm.Create / FsmComponent.AddFsm when the FSM is created
  2. Verify the generic type passed to Start<TState>() matches a registered state and belongs to the same owner type T
  3. Guard with fsm.HasState<TState>() before calling Start to fail fast

Example fix

// before
fsm.Start<IdleState>(); // IdleState never registered
// after
fsm = FsmComponent.AddFsm<FsmOwner>("Player", gameObject,
    new FsmState<FsmOwner>[] { new IdleState(), new WalkState() });
fsm.Start<IdleState>();
Defensive patterns

Strategy: validation

Validate before calling

if (fsm != null && !fsm.HasState<TState>())
    throw new InvalidOperationException($"State {typeof(TState).Name} not registered on FSM");
fsm.Start<TState>();

Type guard

bool IsRegistered<T>(Fsm<T> fsm) where T : class => fsm != null && fsm.HasState<TState>();

Try / catch

try { fsm.Start<TState>(); }
catch (GameFrameworkException ex) { Log.Error("FSM start failed: {0}", ex.Message); }

Prevention

When it happens

Trigger: Calling fsm.Start<SomeState>() (or Start(Type)) where SomeState was not passed in the states array when the FSM was created via FsmComponent.AddFsm / Fsm.Create, or starting a state belonging to a different FSM's owner type.

Common situations: Renaming or deleting a state class without updating the FSM's state list; adding a new state class but forgetting to include it in Create/AddFsm states argument; copy-pasting a Start<TState>() call from another FSM that has different registered states.

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


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

Appendix: source

Thrown at GameFramework/Fsm/Fsm.cs:266

            m_CurrentStateTime = 0f;
            m_IsDestroyed = true;
        }

        /// <summary>
        /// 开始有限状态机。
        /// </summary>
        /// <typeparam name="TState">要开始的有限状态机状态类型。</typeparam>
        public void Start<TState>() where TState : FsmState<T>
        {
            if (IsRunning)
            {
                throw new GameFrameworkException("FSM is running, can not start again.");
            }

            FsmState<T> state = GetState<TState>();
            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), typeof(TState).FullName));
            }

            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.");
            }

View on GitHub (pinned to d0c010b051)