Controlling an NPC's movement speed

Movement Purpose

All supported AI movement commands have a Purpose assigned to them. This purpose allows the AI to identify why that movement is being performed, and to match it against the desired movement speed.

If a function or behavior tree node does not have a parameter for a Purpose, then it is not supported and the speed of the NPC is undefined.

Movement purpose is an extendable StringEnum and new values can be added via datatables.

Vanilla movement purposes are defined both in code and in /Game/Systems/AI/MovementPurposeEnums

Preferred Speeds

An NPC’s preferred movement speed can be adjusted by setting a speed preference on its AIController. This functionality exists at the Conan Basic AIController layer (but does not work for prey).

For example, to make an NPC run while out of combat and walk while in combat, you could do this:

image-20240321-132956.png

Please note that Move Purpose and Combat Purpose are variables in the blueprint so that their enum value can be selected from the dropdown:

image-20240321-133037.png

There is an engine-level bug that causes Behavior Tree Tasks and Services to not properly initialize private EMovementPurpose variables. Variables that are exposed to the behavior tree will initialize properly.

Priorities and multiple preferences

When multiple preferences are set for a single movement purpose, the one with the highest priority takes effect. Default behavior preferences all have a priority of 0.

Reverting preference

When you want to remove a preference (thus allowing the NPC to return to its standard behavior), call Remove Preferred Movement Speed on Conan Basic AIController and supply both the purpose and the source.

The source uniquely identifies a preference. Should a new preference be set, it will overwrite the previous preference from that source.

image-20240321-135210.png

Behavior Tree Preferred Speeds

The preferred speed can also be set on a per-node basis in the behavior tree.

To do so, right click on the node in the tree and add the Service > BTService_SetPreferredMovementSpeed

This service will change the preferred speed while the node (or its children nodes) are active. Note that there’s no point in doing this if you don’t also ensure that movement will at some point having a matching purpose:

image-20240321-140228.png image-20240321-140212.png

Gameplay effect interactions (ie Snared)

The methods described above control the NPC’s BASE movement speed - before any gameplay effects are applied. Effects such as snares or temporary boosts still apply on top of the base speed correctly.

image-20240111-153347.png

Make sure that when applying/removing snares or other effects, that you do so ONLY using the Adjust Movement Speed Multiplier function.