{"id":15160600,"url":"https://github.com/justinleemans/uni-state-machine","last_synced_at":"2026-02-07T05:01:27.077Z","repository":{"id":206567366,"uuid":"715767625","full_name":"justinleemans/uni-state-machine","owner":"justinleemans","description":"Easy state machine package for Unity","archived":false,"fork":false,"pushed_at":"2024-06-19T14:48:27.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-07-24T01:37:55.423Z","etag":null,"topics":["state","state-machine","state-management","unity","unity3d-plugin","upm","upm-package"],"latest_commit_sha":null,"homepage":"","language":"C#","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/justinleemans.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-07T19:45:08.000Z","updated_at":"2024-03-04T19:31:51.000Z","dependencies_parsed_at":"2024-09-22T11:01:25.706Z","dependency_job_id":null,"html_url":"https://github.com/justinleemans/uni-state-machine","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":"0.23076923076923073","last_synced_commit":"62bd06bf8c2fbe7a690be5b2cb49c96a46c7ef82"},"previous_names":["justinleemans/statemachine","justinleemans/uni-state-machine"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/justinleemans/uni-state-machine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinleemans%2Funi-state-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinleemans%2Funi-state-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinleemans%2Funi-state-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinleemans%2Funi-state-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justinleemans","download_url":"https://codeload.github.com/justinleemans/uni-state-machine/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinleemans%2Funi-state-machine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29186742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T03:35:06.566Z","status":"ssl_error","status_checked_at":"2026-02-07T03:34:57.604Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["state","state-machine","state-management","unity","unity3d-plugin","upm","upm-package"],"created_at":"2024-09-26T23:03:28.548Z","updated_at":"2026-02-07T05:01:27.059Z","avatar_url":"https://github.com/justinleemans.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UniStateMachine - Easy statemachine package for Unity\n\nA simple statemachine package for Unity with some usefull features.\n\n# Table of Contents\n\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n- [Contributing](#contributing)\n\n# Installation\n\nCurrently the best way to include this package in your project is through the unity package manager. Add the package using the git URL of this repo: https://github.com/justinleemans/uni-state-machine.git\n\n# Quick Start\n\nTo get started with the statemachine first make sure you have an enum setup with all the states you want to support. See below for an example.\n\n```c#\npublic enum State\n{\n\tInitialization,\n\tLogin,\n\tMenu,\n\tGame\n}\n```\n\n## Instance\n\nAfter you have defined your states you can create an instance of `StateMachine\u003cTState\u003e` where `TState` should be your state. You can use the optional parameter `initialState` to set which state to start from. If not specified the state machine will start from the first state in the list of states.\n\n```c#\nvar stateMachine = new StateMachine\u003cState\u003e(State.Initialization);\n```\n\n## Behaviours\n\nFor every state you should make a new class deriving from `StateBehaviour`. This class will function as the central point of logic for your state.\n\n```c#\npublic class InitializationStateBehaviour : StateBehaviour\u003cState\u003e\n{\n\tpublic void OnEnter()\n\t{\n\t\t...\n\t}\n\t\n\tpublic void OnExit()\n\t{\n\t\t...\n\t}\n}\n```\n\nThe state behaviour will have to required methods to implement. `OnEnter` and `OnExit`. These methods can be used to handle everything you want to happen once a state transition happens. For example you could use this to subscribe and unsubscribe from events.\n\nEach behaviour class also has access to a property called `IsActive` which is a boolean that indicates wheter that state is currently active.\n\n## Component Behaviours\n\nAlternativly you could derive from `MonoStateBehaviour` if you want your behaviour class to be a component. This can be especially helpful if you want to use unity component related methods. This can for example help when building a UI where you want to easily switch windows.\n\n## Configuration\n\nOnce you have made all the necesairy behaviours you can start configuring your state machine. You can use the `SetStateBehaviour()` method on the state machine to set a behaviour per state. This method takes two parameters. First the state you want to configure and second the behaviour instance you want to assign to that state.\n\n```c#\nstateMachine.SetStateBehaviour(State.Initialization, new InitializationStateBehaviour());\n```\n\nAfter all these state behaviours have been assigned you need to define the permissions. You can do this using the `SetPermission()` method. Doing this tells the state machine which states can be accessed from a certain state and which transitions are allowed. In the example below we tell the state machine to allow transitions from `Initialization` to `Login`.\n\n```c#\nstateMachine.SetPermission(State.Initialization, State.Login);\n```\n\nNote that this is a one way permission, if you want to allow the state machine to transition the opposite way you need to define another permission.\n\nThere is also an overload for the `SetPermisson()` method which allows you to make the permitted transition conditional. This way you can permit a transition to happen only when a certain condition is met. For this you can add a predicate method as the last parameter which determines if the condition has been met.\n\n```c#\nbool canTransition = true;\nstateMachine.SetPermission(State.Initialization, State.Login, () =\u003e canTransition);\n```\n\n## Transitioning\n\nTo make the state machine transition from one state to another you can use the `Fire()` method. This method take a state as the only argument which is the state you want the state machine to transition to. This method is available in the `StateBehaviour` class as well as on the state machine directly.\n\n```c#\nstateMachine.Fire(State.Login);\n```\n\nThe state machine also has two method you can use to add/remove a callback which gets called whenever the state machine transitions from one state to another. These methods are called `AddListener()` and `RemoveListener` and both take a delegate with two arguments of the type of your state. These arguments represent the original state and the state it transitioned to.\n\n```c#\nstateMachine.AddListener(OnTransitioned);\nstateMachine.RemoveListener(OnTransitioned);\n\nprivate void OnTransitioned(State source, State target)\n{\n\tDebug.Log($\"Transitioned from {source} to {target}!\");\n}\n```\n\n# Contributing\n\nCurrently I have no set way for people to contribute to this project. If you have any suggestions regarding improving on this project you can make a ticket on the GitHub repository or contact me directly.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinleemans%2Funi-state-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustinleemans%2Funi-state-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinleemans%2Funi-state-machine/lists"}