Skip to content

Custom Nodes

Individual node classes can be extended either through blueprints or C++ allowing logic to be reused throughout different state machine graphs.

States, transitions, conduits, and state machines can have custom classes created.

Creating a Node Class

  1. Right click on your content browser, select State Machines, then Node Class.
  2. You can choose between the base classes you want to inherit from including your own classes you've created.

State Class USMStateInstance

States allow you to override OnStateBegin, OnStateUpdate, and OneStateEnd and is where general logic should go.

  • You can overload various optional functions too which get called at different times.
  • See States for more information on available methods.

/images/NodeClasses/StateClass.jpg

#pragma once

#include "SMStateInstance.h"
#include "SMNativeStateNode.generated.h"  // Your filename.generated.h

UCLASS(Blueprintable, BlueprintType)
class YOURGAME_API USMNativeStateNode : public USMStateInstance
{
public:
    GENERATED_BODY()

protected:
    virtual void OnStateBegin_Implementation() override;
    virtual void OnStateUpdate_Implementation(float DeltaSeconds) override;
    virtual void OnStateEnd_Implementation() override;

};

Rule Behavior for States

Rule behavior for all state type nodes determine if a state should be allowed to be placed in a graph or connected to another state.

Transition Class USMTransitionInstance

Transitions allow you to override CanEnterTransition which is the conditional logic to check if a transition can pass.

  • Any event based transitions will need to be manually bound by utilizing OnTransitionInitialized and OnTransitionShutdown.
  • See Transitions for more information on available methods and event binding.

/images/TransitionClass.JPG

#pragma once

#include "SMTransitionInstance.h"
#include "SMNativeTransitionNode.generated.h"  // Your filename.generated.h

UCLASS(Blueprintable, BlueprintType)
class YOURGAME_API USMNativeTransitionNode : public USMTransitionInstance
{
public:
    GENERATED_BODY()

protected:
    virtual bool CanEnterTransition_Implementation() const override;

};

Rule Behavior for Transitions

Rule behavior for transitions can specify under what conditions this transition class should automatically be placed when making a connection.

Conduit Class USMConduitInstance

Conduits' CanEnterTransition behaves similar to transition classes. The conduit will not pass until the condition is true.

  • Conduits also allow OnStateBegin, OnStateUpdate, and OneStateEnd only when the conduit is configured to operate as a state. This behavior isn't normally available without a custom class.
  • See Conduits for more information on conduits.

State Machine Class USMStateMachineInstance

State machine classes are different from normal state machines (USMInstance) in that they serve more as a type of state machine rather than an actual definition. They also allow you to expose variables on nested FSMs and references.

  • OnStateBegin, OnStateUpdate, and OneStateEnd are available and execute when the state machine starts, is updated, or ends. Hooking into this behavior normally isn't possible without using a custom class.
  • OnStateMachineCompleted is available which fires after the state machine node this class represents has finished.
  • OnEndStateReached is available which fires when an internal end state has become active.

Additional Rule Behavior for State Machine Classes

Special rules are available here to define which state and transition types are allowed be placed within this state machine. This is in addition to the normal state type rules specifying allowed connections.

More

Placing the Class

Custom class nodes can be placed either by selecting them from details panel on a node or by choosing the class from the context menu.

  • Transition classes can only be placed through the details panel or from rule behavior.

https://i.imgur.com/M7HbdSI.gif

Rule Behavior for Node Placement

Depending on the rules you gave the classes they may not show up as options from the context menu or details panel.

Prevent a state from showing up in the context menu

State classes have a Register with Context Menu advanced option which can be unchecked if it should not appear in the context menu.

In C++, specifying NotPlaceable as a UCLASS specifier will prevent a state from being available in the context menu.

UCLASS(NotPlaceable)

Local Graphs

Once a class is assigned it will automatically wire up end points to trigger the instance methods. The local (instanced) graph is available to specify logic which should only happen on this particular node.

https://i.imgur.com/GKoOSm7.gif

Accessing the Node Instance

Calling GetNodeInstance from the local graph returns the instance of the node class assigned. This is similar to a this or self reference of the node.

  • The type is automatically cast to the class of the node.
  • Any variables or methods you defined on the class will be available.
  • If no node class is assigned GetNodeInstance will still work and return the base node type.

Customize the Node Appearance

Certain aspects of the node can be modified to give it a unique appearance, including its name, color, and icon.

Details Panel and Property Info

../images/NodeClasses/StateDetails.jpg

States can optionally hide their name by unchecking Display Name Widget.

Selecting Show Display Name Only and leaving Display Name Widget on will only display the custom Name, regardless of the true state name.

Each property is documented and can be viewed through tooltips or under the appropriate class documentation:

../images/NodeClasses/TransitionDetails.jpg

Transitions have many of the same options states do, and can also move their icon position in the graph.

Each property is documented and can be viewed through tooltips or under the appropriate class documentation:

Changing the Color

../images/NodeClasses/NodeColorDetails.jpg

A node can be given a custom color either in the class defaults or on the instance in the graph.

  • Use Custom Colors must be enabled before Node Color is recognized.

All state types and transitions can have their color changed.

Changing the Icon

../images/NodeClasses/NodeIconDetails.jpg

Set an icon for the node to be displayed in the graph.

  • Display Custom Icon must be enabled before Node Icon is recognized.
  • Node Icon Size left at [0, 0] will default to the full size of the icon. This may need to be set to a smaller size, like [32, 32].

All state types and transitions can have an icon assigned.

Programmatically Modifying the Node

The color, icon, and more can be changed dynamically through Editor Construction Scripts.