{"id":13525995,"url":"https://github.com/tavurth/godot-simple-state","last_synced_at":"2026-02-22T16:38:39.786Z","repository":{"id":38687842,"uuid":"461145238","full_name":"tavurth/godot-simple-state","owner":"tavurth","description":"A simple Finite State Machine for Godot","archived":false,"fork":false,"pushed_at":"2023-12-11T03:25:47.000Z","size":49,"stargazers_count":62,"open_issues_count":0,"forks_count":3,"subscribers_count":7,"default_branch":"4.x","last_synced_at":"2024-11-02T10:34:07.579Z","etag":null,"topics":["finite-state-machine","fsm-library","godot","godot-engine"],"latest_commit_sha":null,"homepage":"https://godotengine.org/asset-library/asset/1242","language":"GDScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tavurth.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":"FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"tavurth","patreon":"tavurth"}},"created_at":"2022-02-19T09:33:45.000Z","updated_at":"2024-08-09T19:22:30.000Z","dependencies_parsed_at":"2023-12-11T07:04:42.417Z","dependency_job_id":null,"html_url":"https://github.com/tavurth/godot-simple-state","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tavurth%2Fgodot-simple-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tavurth%2Fgodot-simple-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tavurth%2Fgodot-simple-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tavurth%2Fgodot-simple-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tavurth","download_url":"https://codeload.github.com/tavurth/godot-simple-state/tar.gz/refs/heads/4.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246596662,"owners_count":20802865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["finite-state-machine","fsm-library","godot","godot-engine"],"created_at":"2024-08-01T06:01:24.145Z","updated_at":"2026-02-22T16:38:39.749Z","avatar_url":"https://github.com/tavurth.png","language":"GDScript","funding_links":["https://github.com/sponsors/tavurth","https://patreon.com/tavurth","https://www.buymeacoffee.com/tavurth"],"categories":["Modules","GDScript"],"sub_categories":["3D"],"readme":"# Godot Simple State\n\nA clean and easy to use Finite State Machine (FSM) for Godot 3.x\n\n[![img](https://awesome.re/mentioned-badge.svg)](https://github.com/godotengine/awesome-godot)\n![img](https://img.shields.io/github/license/tavurth/godot-simple-state.svg)\n![img](https://img.shields.io/github/repo-size/tavurth/godot-simple-state.svg)\n![img](https://img.shields.io/github/languages/code-size/tavurth/godot-simple-state.svg)\n\n\u003ca id=\"org4aefb14\"\u003e\u003c/a\u003e\n\n# Usage\n\n1.  Install the plugin\n2.  Enable the plugin\n3.  Add a `SateMachine` node to your character\n\n    \u003cimg width=\"342\" alt=\"Screenshot 2022-02-19 at 12 36 45\" src=\"https://user-images.githubusercontent.com/100964/154795429-effb016d-1d2b-4719-b4f9-8dc14f6e23c1.png\"\u003e\n\n4.  Add any type of `Node` to the `StateMachine` as a child to create a new script\n\n    \u003cimg width=\"343\" alt=\"Screenshot 2022-02-19 at 12 36 30\" src=\"https://user-images.githubusercontent.com/100964/154795416-322c85d7-8557-42a3-9b49-e3607a798512.png\"\u003e\n\n5.  Attach a script to the node\n6.  Now at runtime you can change to a different state using `$StateMachine.goto(\"state\")`\n\n# Example\n\nThe example project contains two states, `idle` and `attack`.\nThe project will switch between each state automatically every 3 seconds.\n\n# State functionality\n\nThe state has a few functionalities, here is an example state:\n\n```ddscript\nextends Node2D\n\nvar States\nvar Host\n\nfunc _state_enter(arg or not):\n    pass\n\nfunc _state_exit():\n    pass\n```\n\nIf you call `await` in `_state_exit` the `StateMachine` will wait for your `await` to finish before entering the new state.\nThis is also true for `_state_enter` or other state functions.\n\n```gdscript\nfunc _state_exit():\n    await get_tree().create_timer(1).timeout\n```\n\n### Note: Exit state\n\n`state` will change to `_exit` when the state machine is exiting.\nYour state will also be queue-freed.\n\nIf running a long while loop in your state logic, be sure to check for `States.is_current()`\n\n# Reference\n\n## StateMachine\n\n### `signal` `state_changed(new_state)`\n\nEmitted whenever the `StateMachine` changes state (but before `_state_enter` is called)\n\n### `goto(state_name: String, args = null)` change the state\n\n`args` can be any or `undefined`\n\nWhen an arg is passed, the argument will be pushed to the `_state_enter` function.\n\n```gdscript\nStateMachine.goto(\"attack\")\nStateMachine.goto(\"attack\", some_character)\nStateMachine.goto(\"attack\", [some_character_a, some_character_b])\n```\n\nThe last example would call this function in the `attack` state:\n\n```gdscript\nfunc _state_enter(some_characters: Array):\n    ...\n```\n\n### `call(method: String, args = null)` call a function on the current state (if exists)\n\n```gdscript\nStateMachine.call(\"some_method\")\nStateMachine.call(\"some_method\", my_argument)\nStateMachine.call(\"some_method\", [my_arguments])\n```\n\n### `now(state: String)`\n\nReturns true if the current state matches `state`\n\n```gdscript\nif States.now(\"afraid\"):\n    # keep running away instead of stopping to look at something\n```\n\n### `has(state: String)`\n\nReturns true if \u003cstate\u003e exists in our state tree\n\n```gdscript\nif States.has(\"some-other-state\"):\n    # Do something\n```\n\n### `is_current()`\n\nReturns true only when called from a function inside the current state\n\n```gdscript\nif States.is_current():\n    This can only be printed in the current state\n    In any other state this will never be printed\n```\n\n### `restart(arg: any or none)`\n\nRestarts the current state\nThis only calls \"\\_state_enter\" again\nit does not reset any variables\n\n## State\n\n`_state_enter(args or not)` will be called when the state is entered (each time)\nAn argument is only passed if one was passed. (`StateMachine.goto(\"state\", arg)`)\n\n`_state_exit()` will be called when the state is left (each time)\n\nIf the following variables exist on your state, they will be injected with dependencies as follows:\n\n`Host` is the `NodePath` input into `StateMachine` i.e. your character controller\n\n`States` is the `StateMachine`\n\nIf they do not exist on your state, nothing will be injected.\n\n# Signals\n\nYou can connect signals directly to the `StateMachine` node using the following style:\n\n\u003cimg width=\"1024\" alt=\"Screenshot 2022-02-19 at 13 00 38\" src=\"https://user-images.githubusercontent.com/100964/154796280-646ee238-583e-4688-b279-304023140a54.png\"\u003e\n\nThey will be then automatically sent to the current active state if that state has the handler function defined.\n\n\u003ca href=\"https://www.buymeacoffee.com/tavurth\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy Me A Coffee\" height=\"41\" width=\"174\"\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftavurth%2Fgodot-simple-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftavurth%2Fgodot-simple-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftavurth%2Fgodot-simple-state/lists"}