-
Notifications
You must be signed in to change notification settings - Fork 125
Using 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.
-
Download the latest version of UnityHFSM and copy it into your project files.
-
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. -
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 customCoState
class around it.Files to remove or edit:
-
States/CoState.cs
-
Transitions/TransitionOnKey.cs
-
Transitions/TransitionOnMouse.cs
-
-
Edit the
Timer
class.For timekeeping UnityHFSM uses the
Timer
class which relies on Unity'sTime.time
property. Go into theUtil/Timer.cs
file and replace the references toTime.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 withTime.GetTicksMsec() / 1000f
.
With these changes in place, you're ready to use UnityHFSM outside of Unity 👍.