{"record":{"id":"af7250ed77ba2375","repo":"EllanJiang/GameFramework","slug":"fsm-0-can-not-start-state-1-which-is-not-exist","errorCode":null,"errorMessage":"FSM '{0}' can not start state '{1}' which is not exist.","messagePattern":"FSM '(.+?)' can not start state '(.+?)' which is not exist\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Fsm/Fsm.cs","lineNumber":266,"sourceCode":"            m_CurrentStateTime = 0f;\n            m_IsDestroyed = true;\n        }\n\n        /// <summary>\n        /// 开始有限状态机。\n        /// </summary>\n        /// <typeparam name=\"TState\">要开始的有限状态机状态类型。</typeparam>\n        public void Start<TState>() where TState : FsmState<T>\n        {\n            if (IsRunning)\n            {\n                throw new GameFrameworkException(\"FSM is running, can not start again.\");\n            }\n\n            FsmState<T> state = GetState<TState>();\n            if (state == null)\n            {\n                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));\n            }\n\n            m_CurrentStateTime = 0f;\n            m_CurrentState = state;\n            m_CurrentState.OnEnter(this);\n        }\n\n        /// <summary>\n        /// 开始有限状态机。\n        /// </summary>\n        /// <param name=\"stateType\">要开始的有限状态机状态类型。</param>\n        public void Start(Type stateType)\n        {\n            if (IsRunning)\n            {\n                throw new GameFrameworkException(\"FSM is running, can not start again.\");\n            }\n","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Fsm/Fsm.cs#L248-L284","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add the state type to the states array passed to Fsm.Create / FsmComponent.AddFsm when the FSM is created","Verify the generic type passed to Start<TState>() matches a registered state and belongs to the same owner type T","Guard with fsm.HasState<TState>() before calling Start to fail fast"],"exampleFix":"// before\nfsm.Start<IdleState>(); // IdleState never registered\n// after\nfsm = FsmComponent.AddFsm<FsmOwner>(\"Player\", gameObject,\n    new FsmState<FsmOwner>[] { new IdleState(), new WalkState() });\nfsm.Start<IdleState>();","handlingStrategy":"validation","validationCode":"if (fsm != null && !fsm.HasState<TState>())\n    throw new InvalidOperationException($\"State {typeof(TState).Name} not registered on FSM\");\nfsm.Start<TState>();","typeGuard":"bool IsRegistered<T>(Fsm<T> fsm) where T : class => fsm != null && fsm.HasState<TState>();","tryCatchPattern":"try { fsm.Start<TState>(); }\ncatch (GameFrameworkException ex) { Log.Error(\"FSM start failed: {0}\", ex.Message); }","preventionTips":["Keep the state list in one place (a static array) used at FSM creation","Add a startup assertion enumerating all required states with HasState","Compile-time: derive all states from FsmState<T> of the same owner type"],"tags":["unity","fsm","state-not-found"],"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-16T04:17:20.429Z"}