RealDocs

UBlackboardComponent::RegisterObserver

function AIModule Since 4.0
#include "BehaviorTree/BlackboardComponent.h"
Access: public

Description

Registers a delegate that fires whenever the value under the given key changes, the mechanism behind behavior tree decorator observer aborts.

Caveats & Gotchas

  • The delegate signature is EBlackboardNotificationResult(const UBlackboardComponent&, FBlackboard::FKey) — returning RemoveObserver from it unregisters the observer automatically.
  • Notifications are queued (not fired) while observer notifications are paused via PauseObserverNotifications.
  • Always pass a valid NotifyOwner so UnregisterObserversFrom can clean up if you forget to hold the returned FDelegateHandle.

Signature

FDelegateHandle RegisterObserver(FBlackboard::FKey KeyID, const UObject* NotifyOwner, FOnBlackboardChangeNotification ObserverDelegate)

Parameters

Name Type Description Default
KeyID FBlackboard::FKey The blackboard key to watch for changes.
NotifyOwner const UObject* Object that owns the delegate, used to bulk-unregister later via UnregisterObserversFrom.
ObserverDelegate FOnBlackboardChangeNotification Delegate invoked with the blackboard and changed key whenever the key's value changes.

Return Type

FDelegateHandle

Example

Watch a key for changes C++
FBlackboard::FKey TargetKey = BlackboardComp->GetKeyID(TEXT("TargetActor"));
FDelegateHandle Handle = BlackboardComp->RegisterObserver(TargetKey, this,
    FOnBlackboardChangeNotification::CreateLambda([](const UBlackboardComponent& Blackboard, FBlackboard::FKey ChangedKeyID)
    {
        UE_LOG(LogTemp, Log, TEXT("TargetActor changed"));
        return EBlackboardNotificationResult::ContinueObserving;
    }));

Tags

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.