How to Add a New Character State
This guide explains how to add and configure a new character state in RPG Engine v6, using the CharacterStates.Weapons.Reload state as a practical example.
The process involves creating a Gameplay Tag, configuring the rules in DT_CharacterStates, implementing component validation checks via BPI_StateMachine, and triggering the state from the input component.
Step 1: Create the Gameplay Tag
Before adding rules, the state needs a Gameplay Tag.
- Open Project Settings.
- Navigate to the Gameplay Tags section.
- Create a new tag. For this example, the tag is
CharacterStates.Weapons.Reload.
Step 2: Configure DT_CharacterStates
The central rules for the state are defined in DT_CharacterStates.
- Open
DT_CharacterStates. - Add a new row. The Row Name must exactly match the Gameplay Tag (
CharacterStates.Weapons.Reload). - Set the CharacterState field to the newly created tag (
CharacterStates.Weapons.Reload).
Define Component Checks
To ensure the state is only activated when conditions are met, assign components that must validate the request:
- ServerMustPassComponents: Add
Modules.FirearmsComponentandModules.InventoryComponent. The server will query both before allowing the reload. - ClientMustPassComponents: Add
Modules.FirearmsComponent. The client will perform a local check (such as distance to a wall) before sending the request to the server.
Configure Tag Transitions and Restrictions
For the Reload example, configure the remaining fields as follows:
- Necessary Tags For Activating: Leave
Empty. No specific states are required to start a reload. - Forbidden Tags For Activating: Add states that block reloading (for example, various movement or unusual skill states).
- Before Activating Cancel Tags: Set to
CharacterStates.Weapons.Shoot. This ensures shooting is cancelled before reloading starts. - After Activating Cancel Tags: Set to
CharacterStates.Weapons.Aim. This forces the character out of aiming mode when reloading begins. - Remove On Death: Check this box (
true). - Remove After Activation: Check this box (
true). This turns the state into a one-shot activation, meaning it does not need to be manually deactivated later. - Prohibit ReActivation: Check this box (
true).
Step 3: Implement Validation in Components
Components use the BPI_StateMachine interface to validate and execute state logic.
Server Validation (BPI_SM_ServerCheck)
Open the components assigned in ServerMustPassComponents and implement BPI_SM_ServerCheck:
- In
BP_FirearmsComponent: Add logic to check if a firearm is currently held and if it has a clip modification. Returntrueif both conditions are met. - In
BP_EquipmentComponent: Add logic to check if the player has compatible ammo in their inventory, and if the current weapon's ammo count is below maximum. Returntrueif valid.
Client Validation (BPI_SM_ClientPreCheck)
Open the component assigned in ClientMustPassComponents and implement BPI_SM_ClientPreCheck:
- In
BP_FirearmsComponent: Add logic to trace the distance in front of the character. If the character is too close to a wall, returnfalseto block the reload animation. Otherwise, returntrue.
Step 4: Make Components React to the State
If a component needs to execute logic when the state activates, it must register itself and implement the solver function.
- Open
BP_FirearmsComponentandBP_EquipmentComponent. - Locate the
HandleStatesarray variable. - Add
CharacterStates.Weapons.Reloadto the array. If the tag is not in this array, the component will ignore the state activation. - Open the
BPI_SM_ActivateStateSolverfunction inBP_FirearmsComponent. - Add a branch for the
Reloadtag and call your execution logic. For example, callMulticast_PlayReloadMontage.
Note: Because Remove After Activation is true in the data table, you do not need to manually call BPI_MM_DeactivateState for this state. The BPI_SM_DeactivateStateSolver logic will still run automatically after the state has been deactivated.
Step 5: Connect to Input
Finally, bind the state activation to player input. It is recommended to use one InputAction per state for cleaner rebinding logic in the future.
- Create an Input Action, such as
IA_Reload. - Add it to the relevant Input Mapping Context, such as
IMC_OnFoot. - Open
BP_InputsComponent. - Add the
IA_Reloadevent. - From the Pressed execution pin, call the internal
ActivateStatewrapper function (which passes the call toBPI_MM_ActivateStateon theBP_ModulesMediator). - Pass
CharacterStates.Weapons.Reloadas the parameter.
The engine and the mediator will automatically handle routing the activation request from the client to the server, running the validation checks, and executing the solver logic across all registered components.