Skip to Content
AwakenUnreal pluginThe Awaken Npc component

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.

PropertyTypeUse
NpcIdFStringA stable id. Empty: the owning actor’s object name.
DisplayNameFStringThe name shown in the debug views. Empty: the actor’s label.
StatusFStringA short state: Idle, Patrolling.
GoalFStringThe goal the NPC is working on now.
GoalsTArray<FString>The goal list, most important first.
BlackboardTMap<FString, FString>Blackboard keys and text values.
TreeJsonFStringA behaviour tree snapshot: any JSON object. Multi-line in the editor.

Functions

FunctionBehaviour
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() constThe 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 SetBlackboardBool on the subsystem with the id from GetRegisteredId.
  • 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 NpcId for an actor that is spawned at run time. Its default object name depends on spawn order.

Next steps

Last updated on