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; +};