/unreal-skills:npc_logicfrom Unreal Harness Skills
Advises on architecting complex NPC AI in Unreal Engine using a layered model with StateTree, perception, and memory. Helps turn behavior specs into tractable structure.
Ships in Unreal Harness Skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Advise on how to build complicated NPC AI in Unreal Engine to a spec — and the architecture that makes "complicated" stay tractable instead of collapsing into an unmaintainable mega-tree. This skill teaches one durable shape: a layered pipeline with StateTree as the decision framework and the real intelligence in C++ around it. It works whether the spec is a rifle-armed guard, a skittish prey animal, a patrolling sentry, or a companion that follows and assists.
The job, in one line: take a behavior description and map it onto the five-layer model below — decide what each layer must hold, where the seams fall, and how the StateTree stays shallow while the behavior gets deep.
Design-level and neutral. This skill reasons about and documents architecture — it helps you choose the layers, the senses, the memory shape, the mode graph, and the data knobs, and it can author/inspect StateTree assets through the MCP when asked. It is not a recipe library of pre-built creatures, and it does not hand you a finished behavior — the spec is yours; the structure is what this skill gets right.
The single most important decision in UE AI architecture is where intelligence lives. The failure mode that kills AI projects is putting judgment — target selection, threat scoring, memory, search logic — inside the decision graph, where it becomes a sprawling, un-debuggable, un-testable tangle of nodes.
Treat Unreal's AI systems as orchestration and infrastructure, not the home of game logic:
| Concern | Owner |
|---|---|
| High-level mode flow (which behavior is active, and when it switches) | StateTree (asset-backed graph) |
| Sensing the world | AIPerception (+ custom senses) on the AIController |
| Memory: what we know, who's a threat, how sure we are | C++ awareness component on the pawn |
| Picking a target / scoring a threat / choosing an action | C++ (functions the tree's tasks invoke) |
| Executing an action (fire, cast, move, flee) | C++ tasks → character/component methods or GAS |
| Tunable numbers | DataAssets / per-task instance data |
The guiding rule, bolded because everything else follows from it:
Keep the StateTree shallow and asset-light. Put intelligence into C++ components and the tasks/conditions the tree invokes. The tree answers "which mode am I in?" — never "how do I decide who to shoot?"
A good test: if a node would need more than a couple of conditions' worth of branching to express, the logic belongs in C++ behind a single condition or task, not spelled out in the graph.
Data flows up the stack on sensing and down on action. Each layer has a crisp contract with its neighbours, and layers never reach past their neighbour — the decision layer reads memory, never raw perception.
┌─────────────────────────────────────────────┐
spec │ 5. TUNING DataAssets / instance data │ archetype knobs
│ ├─────────────────────────────────────────────┤
│ │ 4. ACTION C++ tasks → methods / GAS │ do the thing
▼ ├─────────────────────────────────────────────┤
│ 3. DECISION StateTree (modes+transitions) │ which mode?
├─────────────────────────────────────────────┤
▲ │ 2. AWARENESS pawn-side memory component │ what we know
│ ├─────────────────────────────────────────────┤
world │ 1. SENSING AIPerception + custom senses │ what we detect
└─────────────────────────────────────────────┘
UAIPerceptionComponent on the AIController, configured with one or more sense configs. The richness of an AI's behavior is bounded by how many distinct signals it can tell apart, so design senses deliberately:
UAISense_Sight) to get a second independently-tuned channel of the same modality. The canonical example is movement-gated far sight: an otherwise-empty UAISense_Sight subclass plus a producer-side stimulus-source component that registers an actor as visible-to-far-sight only while it is moving (velocity over a threshold, with hysteresis). The expensive LOS/cone work stays in UE's native pipeline; cost scales with the number of moving actors, not listeners × actors. Producer-side gating is the general lesson: filter at the source, not per-listener.UAIPerceptionComponent.IGenericTeamAgentInterface and own a real team ID. NoTeam vs NoTeam resolves to Friendly, and friendly stimuli get silently dropped — a classic "my AI ignores the player" bug. State the team model explicitly in any spec with factions.Perception fires on the controller. Its handler filters the stimulus and writes into the pawn's awareness component. It may also drive SetFocus/ClearFocus so control rotation tracks a target. Perception is event-driven — handlers run on stimulus, never per-tick polling.
Pawn-side C++ component(s): written by the controller, read by StateTree nodes. This layer is where "complicated" AI actually gets its depth, and it is the layer most often wrongly skipped (people read perception straight from the tree and then wonder why behavior is jittery and unmemorable).
StateTree nodes read the pawn's awareness component, never the controller's perception directly. This indirection is the whole point: memory persists when perception doesn't, and the tree gets a stable, queryable picture instead of a stream of raw events.
Shape the memory to the spec:
HasValidTarget, IsTargetCurrentlyVisible, HasRecentlyLostTarget, GetLastKnownLocation.StimulusVersion lets a long-running task (e.g. an alert "freeze and watch") detect that a new stimulus arrived mid-hold and react, without re-entering the state.UStateTreeComponent on the AIController, started in OnPossess (StartLogic) and stopped in OnUnPossess. The asset (state graph + transitions) is authored in the editor / via the MCP and assigned on the controller.
UStateTreeComponentSchema sets the context actor to your AIController, so TStateTreeExternalDataHandle<AAIController> resolves and your custom C++ nodes appear in the editor's node picker. No schema → your nodes don't show up.Running/Succeeded/Failed.Asset-coupling gotcha — bolded because it silently bites: after any C++ change to a node's instance-data struct or to the schema types, the StateTree asset must be re-saved, or it fails reference validation at load and the tree silently stops working. Re-save (or recompile via the MCP) after structural C++ changes.
Tasks invoke action semantics that live in C++, not in the graph:
FireAtTarget task calls the character's FireWeapon, which builds the hitscan/projectile params (eye-height origin, control-rotation aim, weapon spread) and executes. Visibility for a "can I shoot?" gate should be perception-authoritative, not a hand-rolled ECC_Visibility trace (a raw trace passes through non-blocking capsules and lies).Selection: fixed vs utility. Start with fixed tasks (one mode → one action). Reach for a utility/action-selector (scoring candidate actions by distance, stamina, pressure, vulnerability window…) only when the spec genuinely has competing actions whose best choice depends on context. Don't build a utility system for an AI that only ever does one thing per mode.
UPrimaryDataAsset): the single knob-set that makes one pawn class behave as many variants by swapping the asset — sense radii/cones, speeds, timing bands, the full alert/flee model, health. Have GetArchetype() fall back to the CDO when none is assigned so tasks never nil-check.UTickableWorldSubsystem, server-only) plus a lightweight per-actor membership component beats every-actor-scans-every-actor. Index members in a spatial hash keyed by group tag, re-bucketed at a low rate. Provide group queries (centroid/nearest/count) and shared per-incident state — e.g. a single mint-once "flee axis" so a panicking group stampedes one direction instead of starbursting. Keep this state world-scoped so PIE restarts and multiple worlds stay clean.eqs_* tools.)AI is server-authoritative. Perception, StateTree execution, target/threat selection, movement authority, and action resolution all run on the server; a group subsystem should refuse to exist on pure clients. Awareness/threat memory is server-only and never replicated — clients receive only the outcomes: replicated movement, animation, and combat results. Replicating the AI's private knowledge is both wasteful and a cheat vector. For the replication discipline itself, cross-reference the networking skill rather than re-deriving it here.
These are consequences of the architecture, not extra work:
bp_inspect/bp_read the controller and pawn, statetree_read / statetree_state_list the current tree, statetree_list_schemas / statetree_list_node_types to see available nodes, ai_get_state / ai_get_perception / ai_get_awareness for runtime introspection, class_inspect / reflection_class_properties for native contracts. Verify; don't assume.Running/Succeeded/Failed mean.statetree_* MCP family creates the asset, adds states/nodes/transitions, binds properties, and compiles it; re-save/recompile after any backing C++ struct change (the coupling gotcha above).ai_get_*, screenshots) — the automated-tester skill formalizes this if a standing test is wanted.Use AskUserQuestion only when the spec genuinely forks (e.g. single-target vs multi-threat, fixed vs utility selection, solo vs group) and you can't infer the intent.
NoTeam faction bugs. Friendly-by-default stimuli silently dropped. → Real team IDs + IGenericTeamAgentInterface.ECC_Visibility passes through non-blocking capsules. → Trust the perception system's "currently sensed."networking; for standing tests use automated-tester; for a written architecture document use architect; for EQS/StateTree tool mechanics see the harness tool contracts (docs/USAGE.md in the harness repo). Cross-reference, don't re-derive.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
unreal-engine, npc-ai, statetree, game-ai, perception-system, ai-architecture
npx claudepluginhub oliver-io/unreal-harness --plugin unreal-skillsOther plugins' skills for the same job
22 skills in this plugin
/architectWrite or update an architecture document for an Unreal Engine system — a conceptual spec a senior engineer can build from. Use when someone wants to "document this system", "write an architecture doc", "spec a feature before building it", "describe how X works for the team", or "update the docs to match the code". Plan-only and code-free: it researches the live editor, Blueprints, and source, then writes a Design-level document about intent, boundaries, contracts, and invariants — no implementation, no builds, no editor mutation. Works in any UE project, not one studio's house style./automated-testerSet up an automated, agent-observed end-to-end test (or a guarded dev loop) for an Unreal feature in this harness. Use when someone wants to "add a test", "test this feature end-to-end", "verify X works in PIE", "build a verification harness", "guard this feature with a test", or "make a guardrail loop for an agent building X". Opinionated: the engine constructs the scenario via typed C++ primitives, the agent observes the behaviour it controls through a DIFFERENT read primitive, no mocks, headless-first. Encodes docs/TESTING.md./bootstrapCreate a new Unreal Engine project under projects/ wired to this repo's UnrealMCP plugin and pre-configured with the recommended engine built-in plugins (Niagara, Water, GeometryScripting, GAS, StateTree, animation, runtime mesh, etc.), and give the project its own agent-facing CLAUDE.md. Use when someone wants to "bootstrap a project", "make a new UE project", "scaffold a test/sandbox project", get a fresh project to drive with the MCP, or "write a CLAUDE.md for this game". Produces a minimal C++ host project that loads the plugin from this repo (no copy) and builds against the engine at UNREAL_ENGINE_ROOT. Asks the intended architecture (C++-first vs Blueprint-first, single- vs multiplayer) and writes a project CLAUDE.md tuned to the answers; can also adopt an existing project by exploring it and writing a CLAUDE.md that describes it.