Variable.Intent 1.0.17

There is a newer version of this package available.
See the version list below for details.
dotnet add package Variable.Intent --version 1.0.17
                    
NuGet\Install-Package Variable.Intent -Version 1.0.17
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Variable.Intent" Version="1.0.17" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Variable.Intent" Version="1.0.17" />
                    
Directory.Packages.props
<PackageReference Include="Variable.Intent" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Variable.Intent --version 1.0.17
                    
#r "nuget: Variable.Intent, 1.0.17"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Variable.Intent@1.0.17
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Variable.Intent&version=1.0.17
                    
Install as a Cake Addin
#tool nuget:?package=Variable.Intent&version=1.0.17
                    
Install as a Cake Tool

GameVariable.Intent

GameVariable.Intent provides a high-performance, zero-allocation Hierarchical State Machine (HSM) implementation. It is designed for AI decision-making, character logic, and complex state management in games.

Installation

dotnet add package Variable.Intent

Features

  • IntentState: A struct-based state machine optimized for performance.
  • Zero Allocation: No garbage collection overhead during state transitions.
  • Event-Driven: Dispatch events to trigger transitions.
  • IIntent Interface: Standard interface for integration.

State Machine Diagram

The IntentState implements the following flow:

stateDiagram-v2
    [*] --> CREATED

    state CREATED {
    }

    CREATED --> WAITING_TO_RUN : ACTIVATED
    CREATED --> WAITING_FOR_ACTIVATION : GET_READY
    CREATED --> CANCELED : CANCEL

    state WAITING_FOR_ACTIVATION {
    }

    WAITING_FOR_ACTIVATION --> WAITING_TO_RUN : ACTIVATED
    WAITING_FOR_ACTIVATION --> CANCELED : CANCEL

    state WAITING_TO_RUN {
    }

    WAITING_TO_RUN --> RUNNING : START_RUNNING
    WAITING_TO_RUN --> CANCELED : CANCEL

    state RUNNING {
    }

    RUNNING --> RAN_TO_COMPLETION : COMPLETED_SUCCESSFULLY
    RUNNING --> WAITING_FOR_CHILDREN_TO_COMPLETE : CHILD_TASK_CREATED
    RUNNING --> FAULTED : UNABLE_TO_COMPLETE
    RUNNING --> CANCELED : CANCEL

    state WAITING_FOR_CHILDREN_TO_COMPLETE {
    }

    WAITING_FOR_CHILDREN_TO_COMPLETE --> RUNNING : ALL_CHILDREN_COMPLETED
    WAITING_FOR_CHILDREN_TO_COMPLETE --> FAULTED : UNABLE_TO_RECOVER
    WAITING_FOR_CHILDREN_TO_COMPLETE --> CANCELED : CANCEL

    state RAN_TO_COMPLETION {
    }

    RAN_TO_COMPLETION --> WAITING_TO_RUN : RUN_AGAIN

    state FAULTED {
    }

    FAULTED --> WAITING_TO_RUN : RECOVER_RETRY
    FAULTED --> CANCELED : UNABLE_TO_RECOVER

Usage

1. Basic State Machine

using GameVariable.Intent;

// Create and start the state machine
var intent = new IntentState();
intent.Start(); // Enters initial state (CREATED)

// Dispatch events to transition
intent.DispatchEvent(IntentState.EventId.GET_READY);
// State: WAITING_FOR_ACTIVATION

intent.DispatchEvent(IntentState.EventId.ACTIVATED);
// State: WAITING_TO_RUN

intent.DispatchEvent(IntentState.EventId.START_RUNNING);
// State: RUNNING

2. Handling Logic Updates

In your game loop, check the state and execute logic:

public void Update()
{
    switch (intent.stateId)
    {
        case IntentState.StateId.RUNNING:
            ExecuteTask();
            if (TaskIsComplete())
                intent.DispatchEvent(IntentState.EventId.COMPLETED_SUCCESSFULLY);
            break;

        case IntentState.StateId.FAULTED:
            Debug.LogError("Task failed!");
            intent.DispatchEvent(IntentState.EventId.RECOVER_RETRY);
            break;
    }
}

3. Hierarchical Tasks

You can use the CHILD_TASK_CREATED event to suspend the current task while a sub-task completes.

// In RUNNING state
if (NeedsSubTask())
{
    SpawnChildTask();
    intent.DispatchEvent(IntentState.EventId.CHILD_TASK_CREATED);
    // State: WAITING_FOR_CHILDREN_TO_COMPLETE
}

// ... later when child completes ...
intent.DispatchEvent(IntentState.EventId.ALL_CHILDREN_COMPLETED);
// State: RUNNING (resumes)

Architecture

This package uses code generation (StateSmith) to produce highly optimized, flat switch-case state machines. The IntentState struct encapsulates the entire state machine logic, ensuring cache coherency and eliminating heap allocations.


Author: Md Ishtiaq Ahamed Fahim
GitHub: iafahim/GameVariable

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.26 97 1/30/2026
1.0.25 91 1/30/2026
1.0.22 98 1/29/2026
1.0.21 93 1/29/2026
1.0.18 91 1/21/2026
1.0.17 92 1/21/2026
1.0.16 95 1/21/2026