The Awaken Npc component
UAwakenNpcComponent is an actor component that lists its owning actor in the Awaken views. It registers the actor with UAwakenDebugSubsystem in BeginPlay and removes it in EndPlay. In the editor it appears as Awaken Npc.
Use the component when one actor is one NPC. Use the subsystem for an NPC with no actor.
Add the component in C++
Create it in the constructor
#include "AwakenNpcComponent.h"
Awaken = CreateDefaultSubobject<UAwakenNpcComponent>(TEXT("Awaken"));
Awaken->DisplayName = TEXT("Gate Guard");
Awaken->Status = TEXT("Idle");Awaken is a UAwakenNpcComponent* member of your actor class.
Update it as the NPC decides
Awaken->SetStatus(TEXT("Patrolling"));
Awaken->SetGoal(TEXT("walk to the north gate"));
Awaken->SetBlackboardNumber(TEXT("round"), 3);To add it in the editor instead, see Register NPCs in Blueprint.
Properties
All properties are in the Awaken category, editable in the editor and readable from Blueprint. They give the NPC its first state.
| Property | Type | Use |
|---|---|---|
NpcId | FString | A stable id. Empty: the owning actor’s object name. |
DisplayName | FString | The name shown in the debug views. Empty: the actor’s label. |
Status | FString | A short state: Idle, Patrolling. |
Goal | FString | The goal the NPC is working on now. |
Goals | TArray<FString> | The goal list, most important first. |
Blackboard | TMap<FString, FString> | Blackboard keys and text values. |
TreeJson | FString | A behaviour tree snapshot: any JSON object. Multi-line in the editor. |
Functions
| Function | Behaviour |
|---|---|
void SetStatus(const FString& NewStatus) | Sets the status. |
void SetGoal(const FString& NewGoal) | Sets the current goal. |
void SetGoals(const TArray<FString>& NewGoals) | Replaces the goal list. |
void SetBlackboardValue(const FString& Key, const FString& Value) | Sets a key to a text value. |
void SetBlackboardNumber(const FString& Key, double Value) | Sets a key to a number. It is published as a JSON number instead of text. |
void RemoveBlackboardKey(const FString& Key) | Removes a key. |
bool SetTreeJson(const FString& NewTreeJson) | Replaces the tree snapshot. Returns false, keeping the previous snapshot, when the text is not a JSON object. |
void PushAll() | Sends every property to the subsystem again. Call it after you edit the properties directly. |
const FString& GetRegisteredId() const | The id this component registered under. Empty before BeginPlay. |
Good to know
- Position. The NPC’s position follows the actor. You do not set it.
- Booleans. The component has no boolean setter. To publish a true or false value, call
SetBlackboardBoolon the subsystem with the id fromGetRegisteredId. - Other components on the actor. When the actor also has a component that reports through
GetAwakenDebugInfo, such as an AgentLoopBT tree, its status, goal, blackboard and tree fill whatever you left empty. What you set yourself wins. See Behaviour trees with AgentLoopBT. - Ids. Set
NpcIdfor an actor that is spawned at run time. Its default object name depends on spawn order.
Next steps
- Register NPCs in C++ with the subsystem.
- In-game panel, HUD and debugger.
Last updated on