Skip to content

Sein Player Controller

Class · ASeinPlayerController : APlayerController

#include "Player/SeinPlayerController.h"

can be subclassed in Blueprint

The RTS player controller. It handles selection (click, marquee, control groups, focus cycling), turns right-clicks into orders using each unit’s Default Commands, and tracks the Shift, Ctrl and Alt modifiers. It never changes the simulation directly; orders reach it as commands.

Input is wired in Blueprint with the usual Enhanced Input pattern: a Blueprint subclass adds its Input Mapping Context on Begin Play and calls the Handle and Set Held functions from its input action events.

Selection

Set the current selection to a new list of actors. Handles deselecting old actors and selecting new ones. Logs a SelectionChanged observer command.

void SetSelection(const TArray<ASeinActor*>& NewSelection);

Add actors to the current selection (Shift+click).

void AddToSelection(const TArray<ASeinActor*>& ActorsToAdd);

Toggle an actor in/out of the selection (Ctrl+click).

void ToggleSelection(ASeinActor* Actor);

Resolves each actor to the actor that should actually be selected: a game can redirect a pick to another actor, such as a squad member to its squad. Returns the results without duplicates or nulls.

static TArray<ASeinActor*> ResolveSelectionTargets(const TArray<ASeinActor*>& Input);

Clear the entire selection.

void ClearSelection();

Cycle active focus: -1 → 0 → 1 → … → N-1 → -1

void CycleFocus();

Get the currently focused actor, or nullptr if focus is “All”.

ASeinActor* GetFocusedActor() const;

Get the actor currently under the mouse cursor.

ASeinActor* GetHoveredActor() const;

Get the number of currently selected actors.

int32 GetSelectionCount() const;

The selected actors that are still alive, owned by this player and selectable. Does not change the selection.

TArray<ASeinActor*> GetValidSelectedActors();

Assign current selection to a control group (Ctrl+number).

void AssignControlGroup(int32 GroupIndex);

Recall a control group (number key).

void RecallControlGroup(int32 GroupIndex);

Get the entity handles in a control group (0-9). Returns empty if out of range.

TArray<FSeinEntityHandle> GetControlGroup(int32 GroupIndex) const;

Get the number of entities in a control group.

int32 GetControlGroupCount(int32 GroupIndex) const;

Command

Issue a smart command to all selected entities (or focused entity). Resolves per-entity ability tags via the entity’s DefaultCommands list.

void IssueSmartCommand(const FVector& WorldLocation, ASeinActor* TargetActor);

Issue a smart command with an optional formation guide.

click). Converted to fixed-point + nav-projected sim-side.

void IssueSmartCommandEx(const FVector& WorldLocation, ASeinActor* TargetActor, bool bQueue, const TArray<FVector>& GuidePoints, FGameplayTag FormationTag);

Orders an ability whose targets were picked with the targeter. The targeter calls this once all points are captured. Owner Leader is the entity that acts on the ability, and Points are the captured targets. An empty Points list fires the ability without a target. Respects the Shift queue modifier.

void IssueTargetedAbility(FGameplayTag AbilityTag, FSeinEntityHandle OwnerLeader, const TArray<FSeinTargeterPoint>& Points);

Finds the ground point under the mouse cursor. Units and props under the cursor are ignored, so hovering a unit still returns the ground beneath it. Use this for move destinations. Falls back to a physics trace when the level has no baked ground data. Returns false only when the cursor is off the world.

bool GetGroundPointUnderCursor(FVector& OutWorld) const;

Input

Abort every in-progress input gesture and clear the modifier latches, committing nothing: no selection change, no order issued, and any active targeter session is cancelled. Call from project code whenever gameplay input is interrupted mid-gesture — opening a pause or UMG menu, losing window focus, switching input mode — so no click, drag, or modifier stays stuck held when input returns.

void ResetInputState();

Primary-select press (LMB down): targeter confirm, else arm click/marquee tracking.

void HandleSelectPressed();

Primary-select release (LMB up): finish marquee, else resolve the single-click selection.

void HandleSelectReleased();

Command press (RMB down): targeter cancel, else arm the command-drag tracking.

void HandleCommandPressed();

Command release (RMB up): interpret the click/drag gesture and issue the smart command.

void HandleCommandReleased();

Select cancel — wire the select action’s Canceled pin here. Unlatches the click and marquee state WITHOUT committing anything: no selection change, no marquee resolve. Canceled fires instead of Completed when a cancelable trigger (Tap, Hold, Chorded Action) ends without triggering; plain Down-trigger bindings never fire it, so this wiring is only needed once such a trigger is in play. If the press had been consumed as a targeter confirm, the targeter session is cancelled rather than confirmed.

void HandleSelectCanceled();

Command cancel — wire the command action’s Canceled pin here. Unlatches the command-drag state WITHOUT issuing an order; the sampled drag path is discarded. Canceled fires instead of Completed when a cancelable trigger (Tap, Hold, Chorded Action) ends without triggering; plain Down-trigger bindings never fire it.

void HandleCommandCanceled();

Keyboard camera pan (WASD / arrows). AxisValue scaled by Key Pan Modifier.

void HandleKeyPan(FVector2D AxisValue);

Keyboard camera rotate and tilt. X rotates around the pivot (Q/E) and Y tilts the camera pitch between top-down and flat; both are scaled by Key Rotate Modifier and applied at the camera pawn’s per-second rates (Rotation Speed / Tilt Speed). Bind an Axis2D action; a yaw-only control scheme simply maps no keys onto the Y axis.

void HandleKeyRotate(FVector2D RotateValue);

Mouse-wheel camera zoom. ZoomDelta scaled by Mouse Zoom Modifier; the camera pawn steps its Zoom Step per wheel tick.

void HandleMouseZoom(float ZoomDelta);

Keyboard camera zoom (Z/X). ZoomDelta scaled by Key Zoom Modifier; frame-rate independent — the camera pawn zooms at its Zoom Rate in units per second.

void HandleKeyZoom(float ZoomDelta);

Toggle follow-camera on the focused (or first selected) entity.

void HandleCameraFollow();

Reset camera rotation to north-facing.

void HandleCameraReset();

Middle-mouse camera pan. MouseDelta is calibrated and scaled by Mouse Pan Modifier; ignored while LMB/RMB are held (those own the mouse delta for marquee / formation drags).

void HandleMousePan(FVector2D MouseDelta);

Mouse camera rotate (X = yaw orbit, Y = pitch tilt), per pixel of mouse movement: MouseDelta is calibrated and scaled by Mouse Rotate Modifier and the camera pawn’s Orbit Sensitivity. Ignored while LMB/RMB are held.

void HandleMouseRotate(FVector2D MouseDelta);

Cycle active focus through the selection.

void HandleCycleFocus();

Ping the location under the cursor (crosses the lockstep wire to all clients).

void HandlePing();

Menu / cancel key: broadcasts On Menu Pressed for the UI layer.

void HandleMenu();

Track the Shift modifier (wire Started → true, Completed → false).

void SetShiftHeld(bool bHeld);

Track the Ctrl modifier (wire Started → true, Completed → false).

void SetCtrlHeld(bool bHeld);

Track the Alt modifier (wire Started → true, Completed → false).

void SetAltHeld(bool bHeld);

Action-slot hotkey (0-11): broadcasts On Action Slot Pressed for the UI action panel.

void HandleActionSlot(int32 SlotIndex);

Control-group hotkey (0-9): assigns with Ctrl held, otherwise recalls.

void HandleControlGroup(int32 GroupIndex);

Select all of your units at once — the classic select-army hotkey. Replaces the current selection (adds to it while Shift is held), and does nothing when you own nothing selectable, so the hotkey never empties an existing selection.

Viewport Only limits the sweep to units currently on screen; the default (false) selects your whole army map-wide. Gathers with the same rules as marquee/click selection (your own, selectable, live entities; group members resolve to their group), so wire it straight to an Input Action’s Started pin.

Defaults: bViewportOnly = false.

void HandleSelectAll(bool bViewportOnly = false);

Select every one of your units of the same type as a reference unit — the classic double-click / select-all-of-type gesture. The reference is the unit under the cursor when it is yours (double-click wiring), else the focused unit, else the first selected; with no reference it does nothing. “Type” is the unit’s exact Blueprint class, and group members resolve to their groups, so hovering one rifle soldier grabs every group fielding that soldier type. Replaces the current selection (adds while Shift is held).

Viewport Only (default true) limits the sweep to units currently on screen, the usual double-click convention; pass false for a map-wide type sweep.

Defaults: bViewportOnly = true.

void HandleSelectAllOfType(bool bViewportOnly = true);

Get the world subsystem (cached).

USeinWorldSubsystem* GetWorldSubsystem() const;

Targeter

Get the local-player targeter subsystem (per-PC, survives travel). Returns null on dedicated server / no local player path.

USeinTargeterSubsystem* GetTargeterSubsystem() const;

UI

This player’s current amount of a resource, for UMG bindings. Returns 0 when the resource is not in the player’s catalog or the simulation is not ready. The value updates live as the player earns and spends.

float GetResource(FGameplayTag ResourceTag) const;

This player’s cap for a resource, for current-over-maximum displays. Returns 0 when the resource has no cap or is unavailable.

float GetResourceCap(FGameplayTag ResourceTag) const;

Match

Implement in Blueprint

The match ended and this machine’s world stopped. Result is this player’s (None when the match was aborted); Reason is why it was decided, or why the match ended. Local controllers only.

void OnMatchEnded(ESeinPlayerResult Result, FGameplayTag Reason);

Implement in Blueprint

This player was defeated and the match goes on. They now watch: the view follows a teammate still playing, or the whole map once none is left, and they can give no orders. Show a defeat screen here. Fires once, also when a loaded match finds them defeated. Local controllers only.

void OnDefeated(FGameplayTag Reason);

Command

Overridable in Blueprint, with a native default

Builds the context tags for a right-click from what is under the cursor: Right Click, then Ground for empty ground, or Friendly (your own), Neutral or Enemy for an entity, plus that entity’s own tags. A unit’s Default Commands match on these tags. Override it to add your own context tags.

FGameplayTagContainer BuildCommandContext(ASeinActor* HitActor, const FVector& HitLocation) const;

FSeinOnSelectionChanged OnSelectionChanged

Fired when the selection or active focus changes.

FSeinOnCommandIssued OnCommandIssued · passes FGameplayTag AbilityTag, FVector WorldLocation

Fired when a command is issued (for move markers, attack lines, sound).

FSeinOnActionSlotPressed OnActionSlotPressed · passes int32 SlotIndex

Fired when an action slot hotkey is pressed (0-11). UI action panel listens to this.

FSeinOnMenuPressed OnMenuPressed

Fired when menu/escape is pressed. UI listens for menu toggle or cancel.

FSeinOnCursorUpdated OnCursorUpdated · passes FVector CursorWorld, bool bValidTrace

Fires every frame with the world position under the cursor. Valid Trace is false when the cursor is off the world; ignore those updates.

float KeyPanSpeed · default 1.0f · min 0.0

Editable in class defaults · Blueprint read and write

Scales keyboard camera panning. 1.0 uses the camera pawn’s configured pan speed unchanged.

float KeyRotateSpeed · default 1.0f · min 0.0

Editable in class defaults · Blueprint read and write

Scales keyboard camera rotation and tilt. 1.0 uses the camera pawn’s configured rates unchanged.

float KeyZoomSpeed · default 1.0f · min 0.0

Editable in class defaults · Blueprint read and write

Scales keyboard camera zooming. 1.0 uses the camera pawn’s configured zoom rate unchanged.

float MousePanSpeed · default 1.0f · min 0.0

Editable in class defaults · Blueprint read and write

Scales middle-mouse camera panning. 1.0 is the intended baseline and includes the internal mouse-delta calibration.

float MouseRotateSpeed · default 1.0f · min 0.0

Editable in class defaults · Blueprint read and write

Scales mouse camera rotation and tilt. 1.0 is the intended baseline and includes the internal mouse-delta calibration.

float MouseZoomSpeed · default 1.0f · min 0.0

Editable in class defaults · Blueprint read and write

Scales mouse-wheel camera zooming. 1.0 uses the camera pawn’s configured zoom step unchanged.

TEnumAsByte<ECollisionChannel> SelectionTraceChannel · default ECC_Visibility

Editable in class defaults · Blueprint read and write

World-geometry channel for ground-position fallback. Entity selection, hover, and targeting use Sein Extents independently of collision channels.

float TraceDistance · default 100000.0f

Editable in class defaults · Blueprint read and write

Maximum trace distance for mouse-to-world projection.

int32 ActiveFocusIndex · default -1

Blueprint read-only

Active focus index within the selection. -1 = “All” (commands dispatch to entire selection). 0+ = index into SelectedActors (commands dispatch to only that unit).

bool bIsMarqueeDragging · default false

Blueprint read-only

Whether a marquee drag is currently active (for HUD rendering).

FVector2D MarqueeStart · default FVector2D::ZeroVector

Blueprint read-only

Screen-space start position of the marquee drag.

FVector2D MarqueeCurrent · default FVector2D::ZeroVector

Blueprint read-only

Screen-space current position of the marquee drag.

int32 CameraLogInterval · default 5 · min 0

Editable in class defaults · Blueprint read and write

How often, in simulation ticks, the controller records its camera position for replays. 0 records every tick.

FSeinPlayerID SeinPlayerID

Blueprint read-only

The match slot this controller plays. The Game Mode assigns it and it replicates to the owning client, so selection and ownership checks work there.

bool bIsCommandDragging · default false

Blueprint read-only

Whether a command drag (RMB hold) is currently active.

FVector CommandDragStart · default FVector::ZeroVector

Blueprint read-only

World-space start point of the command drag.

FVector CommandDragCurrent · default FVector::ZeroVector

Blueprint read-only

World-space current endpoint of the command drag.

TArray<FVector> CommandDragPath

Blueprint read-only

Distance-sampled world-space path captured during a command drag (start … current). Fed to the order gesture to build the guide.

float CommandDragSampleDistance · default 100.f

Editable in class defaults · Blueprint read and write

Minimum cursor travel (world cm) between captured drag-path points — even spacing regardless of drag speed, no point spam on a slow drag.

TSoftClassPtr<USeinOrderGesture> OrderGestureClass

Editable in class defaults · Blueprint read and write

Pluggable interpreter for right-click / drag orders → guide + formation. Null → the base USeinOrderGesture (click → blob, drag → line). Point at a subclass to author custom drag semantics (spline, box, path-march, …).

C++ members (3)
  • void BuildPreviewOrder(FVector CursorWorld, FVector& OutAnchor, TArray<FVector>& OutGuidePoints, FGameplayTag& OutFormationTag) const; Compute the order the CURRENT drag/cursor state would produce — the SAME gesture computation OnCommandReleased commits — exposed for the destination preview so preview === commit. OutAnchor = drag start while dragging, else CursorWorld; OutGuidePoints / OutFormationTag come from the active gesture.
  • bool IsQueueModifierHeld() const; Current right-click queue modifier, shared with destination preview.
  • void ReceiveMarqueeSelection(const TArray<ASeinActor*>& ActorsInBox); Called by HUD when marquee box selection completes.