Databrain Documentation
databrain.ccDiscord
  • Welcome
  • Installation / Update
  • Interface
  • DataObject Property Drawer
    • No GUI Implemented - FIX
  • Getting started
  • Guides
    • Add data objects
    • Add data objects at runtime
    • Get initial data
    • Get/Set runtime data
    • Serialize DataObjects
    • Runtime Save & Load
    • Use custom serializer
    • Import
    • Search
    • Custom GUI
    • Custom GUI with Odin Inspector
    • Hierarchy Template
  • Separate DataObjects
  • Using Version Control
  • Attributes
    • DataObject attributes
    • Field attributes
  • API
    • DataLibrary
    • DataObject
  • FAQ
    • Databrain - FAQ
  • Add-ons
    • Events
    • Blackboard
    • Logic
      • Interface
      • Create Graph
      • Execute graph
      • Control flow execution in groups
      • Custom Nodes
        • Asynchronous execution
        • Node Attributes
      • Scene Components
      • Graph Events
      • Finite State Machine
        • Create custom Actions
        • Examples
        • State Machine Nodes
    • Stats
      • Achievements
      • Modifiers
      • Values
      • Progressions
      • Components
      • Nodes
    • Progress
      • Progress Settings
      • Progress Graph
      • Progress Resources
      • Runtime UI Setup
      • API
        • ProgressController
    • Techtree (LEGACY)
      • Techtree Manager
      • Techtree
      • TechtreeResource
      • Techtree UIBuilder
        • Custom Techtree Node Button
        • Tooltip
      • API
    • Localization
      • Localization Manager
      • Localization
      • Examples
      • Components
      • Import
      • API
    • Inventory
      • Getting started
      • Demo
      • Data setup
        • Inventories
        • Slot IDs
        • Items
          • Blueprints
          • Item rarities
        • Money
        • Loot tables
        • Events
      • Runtime UI
        • Setup
    • Dialogue
      • Getting Started
        • Demo
      • Dialogue runtime setup
      • Actors
        • Emotions
      • Localization
      • Audio
      • Animation
      • Variables
      • Custom theme
      • Import
      • Nodes
      • API
        • DialogueController
        • IDialogueUIControl
  • Changelog
    • Databrain - Changelog
      • 1.4.0
      • 1.3.2
      • 1.3.1
      • 1.3.0
      • 1.2.0
      • 1.1.0
      • 1.0.10
      • 1.0.9
      • 1.0.8
      • 1.0.7
      • <= 1.0.6
Powered by GitBook
On this page
  • Create a state machine
  • Add state actions
  • Run conventional nodes
  1. Add-ons
  2. Logic

Finite State Machine

PreviousGraph EventsNextCreate custom Actions

Last updated 1 year ago

With version 1.1.0 Logic comes with state machine nodes which lets you easily create finite state machines. State machine nodes differ from conventional logic nodes as they can listen to OnEnter, OnUpdate and OnExit calls by the state machine controller.

Create a state machine

First we need to create a state machine controller node. This node runs the actual state. Right click on the node canvas and select: StateMachine / FSM Controller

We can now add some state outputs in the node inspector. (for example Wait, Success, Fail)

Add state actions

To perform state actions we need to connect the output of a FSM Controller with an Actions node first. Then we can define as many action outputs as we like.

A state machine action node differs from conventional Logic nodes as they have three state machine states: OnEnter, OnUpdate and OnExit. Here's an example code of an "empty" state machine action node:

public class MyStateAction : StateMachineActionNode
{
    public override void OnEnter()
    {
        // On Enter
    }

    public override void OnExit()
    {
        // On Exit
    }

    public override void OnUpdate()
    {
        // On update is called by the state machine controller node on every tick
    }   
}

Run conventional nodes

State machine nodes can be used along with the conventional logic nodes. To run conventional nodes you can use the action split node. As the name implies - the action split node splits the output of an actions node (OnEnter, OnUpdate, OnExit) and allows you to connect conventional nodes to each output.

  • OnEnter: Called once when entering the state.

  • OnUpdate: Called on every tick.

  • OnExit: Called when exiting the state.

The "Outputs" UI which allows you to modify the outputs on a node can be added on any custom node by using the [NodeAddOutputsUI]. Read more about it:

Simple state machine which waits for an input for a certain time.
Add new outputs (states) to the FSM controller node.
WaitForInput is a state machine action node which is being executed by the actions node.
NodeAddOutputsUI