{"record":{"id":"32b8dc94e12cf549","repo":"EllanJiang/GameFramework","slug":"fsm-0-can-not-change-state-to-1-which-is-not-exist","errorCode":null,"errorMessage":"FSM '{0}' can not change state to '{1}' which is not exist.","messagePattern":"FSM '(.+?)' can not change state to '(.+?)' which is not exist\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Fsm/Fsm.cs","lineNumber":579,"sourceCode":"        {\n            ChangeState(typeof(TState));\n        }\n\n        /// <summary>\n        /// 切换当前有限状态机状态。\n        /// </summary>\n        /// <param name=\"stateType\">要切换到的有限状态机状态类型。</param>\n        internal void ChangeState(Type stateType)\n        {\n            if (m_CurrentState == null)\n            {\n                throw new GameFrameworkException(\"Current state is invalid.\");\n            }\n\n            FsmState<T> state = GetState(stateType);\n            if (state == null)\n            {\n                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));\n            }\n\n            m_CurrentState.OnLeave(this, false);\n            m_CurrentStateTime = 0f;\n            m_CurrentState = state;\n            m_CurrentState.OnEnter(this);\n        }\n    }\n}\n","sourceCodeStart":561,"sourceCodeEnd":589,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Fsm/Fsm.cs#L561-L589","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nFsm<T> fsm = Fsm<T>.Create(name, owner); // no states registered\nfsm.ChangeState(typeof(IdleState)); // throws\n// after\nFsm<T> fsm = Fsm<T>.Create(name, owner, new IdleState(), new MoveState());\nfsm.ChangeState(typeof(IdleState)); // OK","handlingStrategy":"validation","validationCode":"if (fsm.GetState(typeof(TargetState)) == null) throw new InvalidOperationException(\"Target state not registered in this FSM\");","typeGuard":null,"tryCatchPattern":"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 */ }","preventionTips":["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"],"tags":["fsm","state-machine","missing-state"],"backgroundTag":"resource-not-found","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}