Skip to content

Using UnityHFSM outside of Unity

Inspiaaa edited this page Sep 17, 2023 · 2 revisions

How to use UnityHFSM outside of Unity

Let's say your designing a game or project in a framework / game engine other than Unity (e.g. Godot, Monogame, ...) and want to use UnityHFSM.

Is this possible?

Well, as ridiculous as this may sound, by making a few small changes yourself this is definitely possible.

Although UnityHFSM has some features that are specifically designed for Unity, the core of the library is universal and can be used in any environment. I have made an effort to minimise its reliance on the tools and features provided by Unity.


  1. Download the latest version of UnityHFSM and copy it into your project files.

  2. Delete the .meta and .asmdef files.

    .meta files are special files created by Unity that contain additional metadata to accompany the project assets. They are not relevant and not needed in an environment outside of Unity.

    .asmdef files are "assembly definitions" which are a feature specific to Unity. They group together multiple scripts into an assembly which is also not needed outside of Unity.

  3. Remove features specific to Unity.

    Some features, such as the ability to run coroutines, are built on top of Unity. On one hand you can simply remove them. This is probably the easiest path, as some of the classes are not needed very frequently (e.g. TransitionOnMouse...). On the other hand you could rewrite them yourself, which would take a bit more time. For example, if you want to use coroutines in Godot, you could use my library HCoroutines and build a custom CoState class around it.

    Files to remove or edit:

    • States/CoState.cs

    • Transitions/TransitionOnKey.cs

    • Transitions/TransitionOnMouse.cs

  4. Edit the Timer class.

    For timekeeping UnityHFSM uses the Timer class which relies on Unity's Time.time property. Go into the Util/Timer.cs file and replace the references to Time.time with the equivalent in the framework or game engine that you are using. For example, if you are using Godot 4, you can replace these references with Time.GetTicksMsec() / 1000f.

With these changes in place, you're ready to use UnityHFSM outside of Unity 👍.

Clone this wiki locally