Using with C++¶
C++ can be used to manage instances. Assembling state machines should only be done using the state machine blueprint editor.
Naming¶
All types generally start with SM
(USM, FSM, etc) and follow Unreal Engine naming conventions.
SM is for State Machine
Most of the core plugin was written before settling on "Logic Driver". "FSM" was a nice coincidence for structs!
Build.cs¶
In your [PROJECT].Build.cs
file add SMSystem
to PublicDependencyModuleNames.
PublicDependencyModuleNames.AddRange(new string[]
{
"Core", "CoreUObject", "Engine", "InputCore", "SMSystem"
});
Mac OS and Logic Driver Pro
For Mac OS and Logic Driver Pro add the following to your [PROJECT].Build.cs
:
if (Target.Type == TargetType.Editor)
{
PrivateDependencyModuleNames.AddRange(
new string[]
{
"SlateCore"
}
);
}
This prevents a compile error for FTextBlockStyle
. TextBlockStyle is used to edit the widget of exposed properties and only required for the editor.
File Usage¶
Include the utility header for instantiating instances:
- An instance class is USMInstance.
- An instance can be instantiated by calling USMBlueprintUtils::CreateStateMachineInstance().
- You can also use a USMStateMachineComponent which can support replication. See the Unreal Documentation on attaching a component in C++.
Instantiating and Running a State Machine Instance (Non-Component)¶
StateMachine = USMBlueprintUtils::CreateStateMachineInstance(StateMachineClass, YourContext);
StateMachine->Start()
The StateMachineClass
is a subclass of USMInstance
, and YourContext
is the object the state machine should run for. Just call Start()
when you are ready.
Memory Management
Make sure you assign your instance to a UPROPERTY
! The instance is a UObject and may be garbage collected by Unreal Engine otherwise. When you do want it garbage collected, null out the reference and make sure there are no other strong references to it.
Creating Nodes with C++ ¶
Logic Driver Pro supports designing custom node classes through C++. See the Pro Quickstart Guide. You will still need to use the state machine blueprint editor to design the state machine itself.
C++ Example¶
Below we extend USMStateInstance which is a state class that can be placed in a state machine graph. Notice that OnStateBegin_Implementation
, OnStateUpdate_Implementation
, and OnStateEnd_Implementation
are overidden. This allows you to execute state logic in C++ rather than blueprints. See the USMStateInstance class for all virtual _implementation
methods you can override.
Below is an example implementation of OnStateBegin
and how to use the context passed into the state machine.
You can also create transitions, conduits, and state machine node types in C++.
Example Project¶
See the Dialogue Plugin for an example C++ implementation of node classes.