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¶
- Right click on your content browser, select
State Machines
, thenNode Class
. - You can choose between the base classes you want to inherit from including your own classes you've created.
- Inherit from USMStateInstance, USMTransitionInstance, USMConduitInstance, or USMStateMachineInstance.
- Overload the virtual
_Implementation
methods, such asOnStateBegin_Implementation
.
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.
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
andOnTransitionShutdown
. - See Transitions for more information on available methods and event binding.
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
, andOneStateEnd
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
, andOneStateEnd
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.
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.
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.
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.
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
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:
- NodeInstance
- Inherited properties for all node types.
- StateInstance_Base
- Inherited properties for all state types.
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:
- NodeInstance
- Inherited properties for all node types.
- TransitionInstance
- Inherited transition properties.
Changing the Color¶
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 beforeNode Color
is recognized.
All state types and transitions can have their color changed.
Changing the Icon¶
Set an icon for the node to be displayed in the graph.
Display Custom Icon
must be enabled beforeNode 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.