RealDocs

UBlackboardComponent::GetValueAsClass

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

Description

Returns the UClass value stored under the given blackboard key. Used to read a stored actor/pawn class, such as a class chosen by a behavior tree decorator or task.

Caveats & Gotchas

  • Returns nullptr for a missing key, a key of the wrong type, or a key that was never set — there is no way to distinguish these cases from the return value alone.
  • Key lookup is by FName every call; cache the FBlackboard::FKey via GetKeyID() and use the key-ID overload of the underlying template accessor in hot paths.
  • The stored class must have been set with a compatible base class restriction on the blackboard key, otherwise SetValueAsClass silently rejects incompatible values.

Signature

UClass* GetValueAsClass(const FName& KeyName) const

Parameters

Name Type Description Default
KeyName const FName& The name of the class blackboard key to read.

Return Type

UClass*

Example

Spawn an actor using a class stored in the blackboard C++
if (UClass* SpawnClass = BlackboardComp->GetValueAsClass(TEXT("TargetClass")))
{
    GetWorld()->SpawnActor<AActor>(SpawnClass, SpawnTransform);
}

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.