From 6d8169e2b3b9ffa15dc480548fe48b9838dcdf94 Mon Sep 17 00:00:00 2001 From: Louis Hobbs Date: Wed, 23 Aug 2023 00:20:02 +0100 Subject: [PATCH] Add StoreActorLocationTask AI Task Node --- Source/Nakatomi/StoreActorLocationTask.cpp | 29 +++++++++++++++++++ Source/Nakatomi/StoreActorLocationTask.h | 33 ++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 Source/Nakatomi/StoreActorLocationTask.cpp create mode 100644 Source/Nakatomi/StoreActorLocationTask.h diff --git a/Source/Nakatomi/StoreActorLocationTask.cpp b/Source/Nakatomi/StoreActorLocationTask.cpp new file mode 100644 index 0000000..d9f72ab --- /dev/null +++ b/Source/Nakatomi/StoreActorLocationTask.cpp @@ -0,0 +1,29 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "StoreActorLocationTask.h" +#include "NakatomiCharacter.h" +#include "BehaviorTree/BlackboardComponent.h" + +UStoreActorLocationTask::UStoreActorLocationTask() +{ +} + +EBTNodeResult::Type UStoreActorLocationTask::ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) +{ + auto blackboardComponent = owner.GetBlackboardComponent(); + auto playerCharacter = Cast(blackboardComponent->GetValueAsObject(TargetActor.SelectedKeyName)); + + if (playerCharacter) + { + blackboardComponent->SetValueAsVector(TargetActorLocation.SelectedKeyName, playerCharacter->GetActorLocation()); + return EBTNodeResult::Succeeded; + } + + return EBTNodeResult::Failed; +} + +EBTNodeResult::Type UStoreActorLocationTask::AbortTask(UBehaviorTreeComponent& owner, uint8* memory) +{ + return EBTNodeResult::Aborted; +} diff --git a/Source/Nakatomi/StoreActorLocationTask.h b/Source/Nakatomi/StoreActorLocationTask.h new file mode 100644 index 0000000..98435e1 --- /dev/null +++ b/Source/Nakatomi/StoreActorLocationTask.h @@ -0,0 +1,33 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTTaskNode.h" +#include "StoreActorLocationTask.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UStoreActorLocationTask : public UBTTaskNode +{ + GENERATED_BODY() + +private: + UPROPERTY() + UBehaviorTreeComponent* behaviourTreeOwner = nullptr; + + UPROPERTY(EditAnywhere, Meta = (AllowPrivateAccess = "true")) + FBlackboardKeySelector TargetActor; + + UPROPERTY(EditAnywhere, Meta = (AllowPrivateAccess = "true")) + FBlackboardKeySelector TargetActorLocation; + +public: + UStoreActorLocationTask(); + + virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override; + + virtual EBTNodeResult::Type AbortTask(UBehaviorTreeComponent& owner, uint8* memory) override; +};