StateMachineKit.Godot
0.1.0
dotnet add package StateMachineKit.Godot --version 0.1.0
NuGet\Install-Package StateMachineKit.Godot -Version 0.1.0
<PackageReference Include="StateMachineKit.Godot" Version="0.1.0" />
<PackageVersion Include="StateMachineKit.Godot" Version="0.1.0" />
<PackageReference Include="StateMachineKit.Godot" />
paket add StateMachineKit.Godot --version 0.1.0
#r "nuget: StateMachineKit.Godot, 0.1.0"
#:package StateMachineKit.Godot@0.1.0
#addin nuget:?package=StateMachineKit.Godot&version=0.1.0
#tool nuget:?package=StateMachineKit.Godot&version=0.1.0
StateMachineKit
StateMachineKit is a flexible, plug-and-play finite state machine (FSM) toolkit for .NET / game development.
It provides a lightweight abstraction for defining states, transitioning between them, and integrating with engines
(such as Godot via the companion StateMachineKit.Godot
package).
Packages
Package | Version | Description |
---|---|---|
StateMachineKit | 2.0.0 | Core abstractions (interfaces, discovery attribute, helpers) supporting .NET 8 and .NET Standard 2.1. |
StateMachineKit.Godot | 0.0.1 | Godot (C#) integration layer depending on the core package. |
Key Features
- Generic, owner-driven state machine:
IStateMachine<TContext>
/IState<TContext>
- Attribute-based automatic state discovery (
[DiscoverableState]
) - Extension methods for ticking (Update / FixedUpdate)
- Pluggable design; you keep your concrete state definitions decoupled
- Godot integration package for engine-specific hooks
Quick Start (Core)
public sealed class IdleState : IState<MyActor> { /* ... */ }
public sealed class MoveState : IState<MyActor> { /* ... */ }
// Assuming you've already defined classes
// that implement IStateMachine and IStateOwner.
var actor = new MyActor("Player");
var fsm = FiniteStateMachine.Create(actor);
fsm.Initialize<IdleState>();
// In your update loop
fsm.Tick(deltaTime);
Godot Integration
Install the StateMachineKit.Godot
NuGet package and reference it from your Godot C# project. The Godot layer
adds engine-friendly owner definitions and can be extended to tie into lifecycle callbacks (_Process
, _PhysicsProcess
).
For now, the only useful class within the Godot module is GodotState, which implements the IState<TContext>
interface and contains virtual methods.
The state owner and state machine implementations proved redundant, as Godot does not load GlobalClass
es from external Assemblies.
With that in mind:
Quick Start (Godot)
// First, define a global class extending the Godot node you want to manage states for, and implementing IStateOwner.
[GlobalClass]
public partial class Player : CharacterBody2D, IStateOwner{ /* ... */ }
// Then, in another file:
[GlobalClass]
public partial class PlayerStateMachine : Node, IStateMachine<Player> {
// You're expected to write some logic of your own, depending on how you would like to manage States.
// The current recommended way is to use Reflection to help State Machines discover State classes that meet
// the criteria you set. This is the code snippet I provide as a reference:
private readonly Dictionary<Type, IState<Player>> _states = new();
private void FindAllStates()
{
_states.Clear();
var stateType = typeof(IState<StateOwner>);
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
foreach (var type in assembly.GetTypes()
.Where(t => stateType.IsAssignableFrom(t)
&& t is { IsInterface: false, IsAbstract: false })
.Where(t => Attribute.IsDefined(t, typeof(DiscoverableStateAttribute))))
if (Activator.CreateInstance(type) is IState<StateOwner> instance)
_states[type] = instance;
}
// . . .
}
// And then, you can declare your state classes by implementing IState<Player>, or extending GodotState<Player>.
StateMachineKit also provides a DiscoverableStateAttribute
that you can use to separate classes you actually want to register in state machines.
It is recommended that you cache each set of states after discovery for optimization purposes.
Versioning
- Core at 2.0.0 introduces improved initialization semantics and packaging metadata
- Godot integration starts at 0.0.1 (early preview)
Roadmap
- Source generator for compile-time state registration
- Transition validation & visualization hooks
- Async lifecycle (optional)
Contributing
Issues and PRs are welcome. Please include tests for behavioral changes.
License
MIT – see license.md
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- GDExternalGlobalizer.Generator (>= 0.1.2)
- Godot.SourceGenerators (>= 4.4.1)
- GodotSharp (>= 4.4.1)
- GodotSharpEditor (>= 4.4.1)
- StateMachineKit (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.