Skip to content

Write a Custom Movement Mode

Goal. A flying Skiff that accelerates, brakes into its destination, banks into turns, coasts to a stop when ordered to stand, and flies straight over the terrain at a fixed altitude. Each Skiff can be tuned separately.

Add the Truck builds a small mode with Compute Motion. This page goes further: it keeps a unit’s momentum, overrides the idle step, marks the hooks Thread Safe so the mode steps in parallel, and passes per-unit tuning through Mode Data. Read Movement first for what the harness does around your mode.

You need a unit that already moves, such as the Soldier from Add Movement, and a Move ability.

In the Content Browser, right-click and choose SeinARTS > Movement Mode (parent Sein Movement). Name it SM_Skiff.

Open Class Defaults and set the traits:

Setting Value Why
Bypass Pathfinding On The Skiff flies straight over obstacles. Its route is a straight line
Snaps To Ground Off It rides over the top of any cell and does not tilt to the slope

Leave Ticks While Idle off. An idle unit then sleeps once it has stopped. Turn it on only for a mode that must keep running while it stands still, as a hover bob does.

Add these variables, all Fixed Point and Instance Editable:

Variable Default Meaning
Acceleration 400 Speed gained per second
Braking 600 Speed lost per second, when slowing for the destination or coasting
MaxBank 0.5 The most the Skiff rolls, in radians (about 29 degrees)
CruiseAltitude 400 How far above the ground it flies

Only Instance Editable variables of a deterministic type (fixed point, integer, boolean, enum) become tuning. A float variable cannot be tuning, and data validation flags floats in a mode.

In Class Defaults, under Tuning, press Generate Tuning Data Structure. It writes a struct named SM_SkiffTuningData beside the mode, with one field per variable, and links it. Run it again whenever you add, remove or retype a variable. A message tells you the struct it made. If none is made, no variable qualified.

Override Get Altitude and return CruiseAltitude. It runs inside the step, so tick Thread Safe in the function’s Details.

The harness adds this to the ground height. A unit snaps to it on its first idle step, using the mode’s class default. After that, height changes at up to the unit’s Speed. Because the function reads CruiseAltitude as a variable, one function serves every Skiff: each takes its own value once Mode Data is copied at the start of its first move (see section 8).

Override Compute Motion and tick Thread Safe. It receives a Mover handle. The graph:

  1. Direction. Get Destination minus Get Location. Break the difference, then Make FixedVector from its X, Y and Fixed-point Zero, so height does not shorten the horizontal vector. Get Safe Normal gives Direction.
  2. Current speed. Vector Size of Get Velocity. Because the unit’s velocity from the last tick carries over, the Skiff remembers its speed without any state in the mode.
  3. Target speed. Get Arrival Speed Cap with Distance To Stop from Get Distance To Destination minus Get Acceptance Radius, and Deceleration Braking. It is the fastest the Skiff can go and still stop at the edge of its acceptance radius, where the harness ends the move and zeroes its velocity. Take the Min of it and Get Speed.
  4. New speed. Step Speed Toward with Current the current speed, Target the target speed, Acceleration Acceleration and Deceleration Braking.
  5. Velocity. Direction multiplied by the new speed.
  6. Heading. Atan 2 with Y and X of Direction.
  7. Bank. Shortest Angle Delta from Get Yaw to the heading, Clamped between Negate MaxBank and MaxBank. Call Set Render Value with that, under a tag such as SeinARTS.Render.Bank (add the tag when prompted).
  8. Return. Make Sein Motion with Velocity, Target Yaw the heading, and Update Facing on.

The Skiff does not call Resolve Avoidance. Basic Avoidance ignores bodies that bypass ground navigation anyway. A ground mode would add it between steps 5 and 6, and set Hold on the motion if avoidance asks the unit to wait.

You never move the unit, check walls or limit the turn. The harness limits the yaw change to Turn Rate for you. Give the Skiff a low Turn Rate such as 2.5 on its Sein Movement component and the heading error in step 7 grows in a sharp turn, so the bank does too.

Override Compute Idle Motion and tick Thread Safe. It runs when the unit has no move, and it replaces the default, which stands still and turns to the formation facing.

  1. Get Velocity: Direction is its Get Safe Normal, and the speed is its Vector Size.
  2. Step Speed Toward with Target Fixed-point Zero, Acceleration Fixed-point Zero and Deceleration Braking. The new speed is lower each tick.
  3. Set Render Value to Fixed-point Zero under the bank tag. A render value cannot be written in On Move End, so the idle step clears it.
  4. Make Sein Motion with Velocity Direction times the new speed, and Update Facing off.

The Skiff now coasts to a stop over speed ÷ Braking seconds when its order is cancelled. Arrival is different: it zeroes the velocity, so there is nothing left to coast on. A mode that overrides this event decides its own facing, so the Skiff no longer turns to a formation slot.

A mode steps in parallel across worker threads when every step hook it overrides is Thread Safe: Compute Motion, Compute Idle Motion and Get Altitude. A mode with any hook not marked steps serially after the parallel step. The result is the same either way. The compile warning names a hook that is not marked:

Compute Motion is not marked Thread Safe, so this mode steps serially after the parallel step.

To mark one, open the function graph, select the function’s entry node and tick Thread Safe in Details. Compile. In Class Defaults, Steps In Parallel now reads on (it is read-only).

What a Thread Safe hook may use:

  • Every Mover handle node except Query Nav Direction, which searches on the game thread.
  • The SeinARTS Math Library: fixed-point arithmetic, trigonometry and vectors.
  • The mode’s own variables, and the hook’s local variables.

Gameplay tag lookups, the entity library, abilities and anything that reads another unit are not thread safe. For other units, use Get Nearby Movers and Resolve Avoidance, which read the tick’s snapshot. A step may write only its own unit, its Movement Data and the mode, so you cannot change another unit from a step. Hooks that run serially, On Move Begin, On Move End and Plan Path, do not need the mark, and may use more.

Hook Use
On Move Begin Runs once when a move starts. Reset per-move state. It runs after Mode Data is copied onto your variables
On Move End Runs when the move completes, fails or is cancelled. Only pose reads work, because the unit has no Movement Data to write
Plan Path Builds the route. The default flies straight for a mode that bypasses pathfinding and asks navigation otherwise

In Plan Path you get a Planner handle: Request Nav Path runs the normal search and leaves the route for you to read (Get Path Waypoint Count, Get Path Waypoint) and rebuild with Clear Path, Add Waypoint and Finalize Path. Add Arc Segment, Add Straight Segment and Add Pivot Segment build a typed route for a vehicle that drives curves and turns in place. The route must end exactly on the destination. A partial route is refused, and the move waits and plans again.

Two properties on the mode tune the stall timers: Replan After No Progress (1 second) and Stranded After No Progress (10 seconds). Raise them for a unit with long legitimate pauses.

On the Skiff’s Blueprint:

Component Settings
Sein Movement Movement Class SM_Skiff. Speed 700. Turn Rate 2.5. Mode Data fills in with your four tuning fields
Sein Navigation Acceptance Radius 150. A fast unit needs a wider stop zone
Sein Abilities SA_Move and SA_Stop, with a Right Click and Target Ground mapping to Move

Set the Mode Data values you want for this unit, such as CruiseAltitude 600 for a high flyer. They are copied onto the mode when each move begins, so a unit that has not moved yet runs on the mode’s class defaults. Set the class defaults to the values you want most Skiffs to have.

Presentation reads the bank the mode wrote. In the Skiff actor’s Event Graph, on Event Tick: Get Movement Render Value (Entity Handle from Get Entity Handle on the actor, Key the bank tag). It returns a float in radians. Radians To Degrees it and set the roll of the mesh with Set Relative Rotation. Use FInterp To if you want the bank smoothed. Render values are not simulation state, so they are never saved or checked, and they cannot affect other players.

Place a Skiff and a camera that sees the whole level. Play and order it 3,000 units away.

  1. It already hovers at the class default CruiseAltitude, and climbs from there if Mode Data sets a higher one. It reaches Speed 700 after 1.75 seconds, having covered about 610 units.
  2. It begins braking about 560 units from the point, and arrives, nearly stopped, 150 units short of it, near 5.5 seconds after the order. If it brakes much earlier or later, check Braking.
  3. It rolls into a turn when you redirect it mid-flight, up to MaxBank.
  4. Order a Stop mid-flight. It drifts to a halt over about a second instead of stopping dead, and levels off.
  5. The Compiler Results for SM_Skiff show no Thread Safe warning.

To see the unit’s movement footprint and velocity, run Sein.Show.Steering.

A native mode derives from USeinMovement in the SeinARTSMovement module. Native modes always step in parallel, so they must obey the thread rule above.

#include "Movement/SeinMovement.h"
#include "SkiffMovement.generated.h"
UCLASS()
class USkiffMovement : public USeinMovement
{
GENERATED_BODY()
public:
virtual FSeinMotion ComputeMotion_Implementation(USeinMoverHandle* Mover) override;
virtual FSeinMotion ComputeIdleMotion_Implementation(USeinMoverHandle* Mover) override;
};
  • The Skiff does not move. Movement Class is empty or points to a mode that did not compile. Check whether the ability’s Move To fires On Failed, and with which reason.
  • It stops hard at the destination. Arrival zeroes the velocity, so Distance To Stop must subtract Get Acceptance Radius. Get Arrival Speed Cap also has no limit when Deceleration is zero or less, so check that Braking has a positive default and that the unit’s Mode Data does not set it to zero.
  • It rides on the ground. Get Altitude returns zero, or CruiseAltitude is zero.
  • The Mode Data fields are missing. Generate Tuning Data Structure was not run, or none of the variables is Instance Editable with a deterministic type.
  • Tuning values do not apply. They are copied when a move begins. Variables you changed on a Mode Data entry take effect from the next move.
  • The mode steps serially. A step hook is not marked Thread Safe. Read the compile warning. Using a node that is not thread safe also gets flagged.
  • Data validation flags a non-deterministic node. The graph uses a float, a random or a time node. Replace it with the fixed-point equivalent.
  • The bank sticks after the Skiff lands. Compute Idle Motion must set the render value to zero. On Move End cannot write it.
  • It slides sideways in turns. The velocity points at the destination at once, while the facing is limited by Turn Rate. Raise Turn Rate, or build the velocity from the facing, as the Truck does, for a car-like feel.