Quick Start¶
Get an NPC with threat tracking, leashing, and patrol running in under 10 minutes.
Prerequisites¶
- FWAISystem plugin installed and enabled
- A Character or Pawn class for your NPC
- An AI Controller assigned to your NPC
- A Behavior Tree asset (or willingness to create one)
Step 1: Create an NPC Definition Data Asset¶
The UFWNpcDefinition data asset is the central configuration for each NPC archetype.
- In the Content Browser, right-click and select Miscellaneous > Data Asset.
- Choose
FWNpcDefinitionas the class. - Name it
DA_ForestWolf(or whatever fits your NPC). - Configure the following fields:
| Section | Field | Value |
|---|---|---|
| Identity | NpcId | ForestWolf |
| Identity | DisplayName | Forest Wolf |
| Identity | Category | Trash |
| Identity | NpcClass | Your wolf Pawn Blueprint |
| AI Behavior | BehaviorTree | Your behavior tree asset |
| AI Behavior | PatrolMode | Random Roam |
| AI Behavior | RoamRadius | 1000 |
| AI Behavior | AggroRadius | 1500 |
| Spawning | RespawnTime | 30 |
| Spawning | MaxActiveInstances | 1 |
Start Simple
Leave Leash, Threat, Scaling, and Faction at their defaults for now. You can fine-tune them later through the Configuration guide.
Step 2: Place a Spawn Point¶
- In the Level Editor, search the Place Actors panel for
FWNpcSpawnPoint. - Drag it into your level at the desired spawn location.
- In the Details panel, set:
- NpcDefinition: Select your
DA_ForestWolfasset. - bSpawnOnBeginPlay:
true - MaxInstances:
1
- NpcDefinition: Select your
The spawn point will show a billboard icon in the editor for easy identification.
Step 3: Add Threat and Leash Components to Your NPC¶
Open your NPC's Blueprint or C++ class and add both components:
- Open your NPC Blueprint.
- Click Add Component and search for
FW Threat Component. Add it. - Click Add Component again and search for
FW Leash Component. Add it.
Automatic Configuration
When spawned by AFWNpcSpawnPoint, the spawn point automatically configures the Threat and Leash components with values from the UFWNpcDefinition data asset. You do not need to manually set leash radii or threat decay rates if they are defined in the data asset.
Step 4: Set Up the Behavior Tree¶
Create a basic behavior tree that uses the built-in FWAISystem nodes.
Recommended Behavior Tree Structure¶
Root
Selector
|
+-- Sequence [Decorator: IsLeashing]
| +-- Task: ReturnToSpawn
|
+-- Sequence [Decorator: HasThreat]
| +-- Service: UpdateThreat
| +-- Service: CheckLeash
| +-- Task: FindThreatTarget
| +-- Task: MoveToTarget
|
+-- Task: Patrol
Adding Nodes¶
- Right-click in the Behavior Tree editor to add nodes.
- Under Tasks, you will find:
FW Find Threat Target-- SetsTargetActorblackboard key to highest-threat actorFW Move To Target-- Moves toward theTargetActor, aborts on leashFW Return To Spawn-- Walks back to spawn, callsResetToSpawnon arrivalFW Patrol-- Random roam or waypoint patrol
- Under Services, you will find:
FW Update Threat-- Adds proximity threat from perceived hostiles, updates blackboardFW Check Leash-- Monitors leash state, updatesNpcStateblackboard key
- Under Decorators, you will find:
FW Has Threat-- Gates combat subtree on threat table having entriesFW Is Leashing-- Gates leashing subtree on hard leash exceeded
Blackboard Setup¶
Create a Blackboard asset with the following keys:
| Key Name | Type | Purpose |
|---|---|---|
TargetActor |
Object (Actor) | Current threat target |
bHasThreat |
Bool | Whether the threat table has entries |
NpcState |
Enum (EFWNpcState) | Current NPC behavior state |
PatrolIndex |
Int | Current waypoint index for patrol |
SpawnLocation |
Vector | Spawn anchor location |
HomeLocation |
Vector | Home/patrol center location |
Step 5: Test in PIE¶
- Press Play in Editor (PIE).
- The spawn point should spawn your NPC automatically.
- Approach the NPC -- if you have AI Perception configured with sight sensing, the
UpdateThreatservice will generate proximity threat. - Attack the NPC to generate damage threat. The NPC should chase you.
- Run far enough away (beyond
LeashRadius, default 4000 cm) -- the NPC should disengage and walk back to its spawn point.
AI Perception Required
The FWBTService_UpdateThreat relies on the NPC's UAIPerceptionComponent to detect nearby hostile actors. Ensure your AI Controller has perception configured with at least a Sight sense.
Step 6: Verify Threat and Leash Behavior¶
To debug threat and leash at runtime:
- Open the Gameplay Debugger (press
'in PIE by default). - Select your NPC.
- Check the BehaviorTree category to see which nodes are active.
- Use
ShowDebug AIin the console to visualize the behavior tree.
You can also print threat values in Blueprint by calling:
GetHighestThreat()-- Returns the actor with the most threatGetThreatValue(Actor)-- Returns a specific actor's threat valueHasThreat()-- Returns true if anyone is on the threat tableGetDistanceFromSpawn()-- Returns distance from spawn anchorIsInSoftLeash()/IsLeashTriggered()-- Check leash state
Next Steps¶
- Configuration -- Tune threat decay rates, leash radii, and scaling parameters
- Tutorials -- Build a full MMO boss with threat, scaling, and faction aggro
- Blueprints -- Complete Blueprint node reference
- API Reference -- Full C++ API documentation