void UBTDecorator_BlueprintBase::OnBecomeRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) { if (AIOwner != nullptr && ReceiveObserverActivatedImplementations & FBTNodeBPImplementationHelper::AISpecific) { ReceiveObserverActivatedAI(AIOwner, AIOwner->GetPawn()); } else if (ReceiveObserverActivatedImplementations & FBTNodeBPImplementationHelper::Generic) { ReceiveObserverActivated(ActorOwner); } if (GetNeedsTickForConditionChecking()) { // if set up as observer, and has a condition check, we want to check the condition every frame // highly inefficient, but hopefully people will use it only for prototyping. bNotifyTick = true; } UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent(); if (BlackboardComp) { for (int32 NameIndex = 0; NameIndex < ObservedKeyNames.Num(); NameIndex++) { const FBlackboard::FKey KeyID = BlackboardComp->GetKeyID(ObservedKeyNames[NameIndex]); if (KeyID != FBlackboard::InvalidKey) { BlackboardComp->RegisterObserver(KeyID, this, FOnBlackboardChange::CreateUObject(this, &UBTDecorator_BlueprintBase::OnBlackboardChange)); } } } }
EBTNodeResult::Type USetNextTargetPoint::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) { Super::ExecuteTask(OwnerComp, NodeMemory); if (!GetWorld()) { return EBTNodeResult::Failed; } //Set the blackboard to make calling it easier in the future UBlackboardComponent* Blackboard = OwnerComp.GetBlackboardComponent(); //Get the ID of the key that we state in the editor uint8 TargetKeyID = Blackboard->GetKeyID(TargetName); //Get the AI so we can call a function on it UObject* SelfActor = Blackboard->GetValue<UBlackboardKeyType_Object>(TargetKeyID); //Cast it to the proper class AShadowAnnaCharacter* ShadowAnna = Cast<AShadowAnnaCharacter>(SelfActor); if (ShadowAnna) { //IF the cast works call the function //FVector NewTarget = ShadowAnna->SetNextTargetPoint(); //Blackboard->SetValue<UBlackboardKeyType_Vector>(BlackboardKey.GetSelectedKeyID(), NewTarget); return EBTNodeResult::Succeeded; } return EBTNodeResult::Failed; }