document.write("
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "AITypes.h"
#include "Abilities/Tasks/AbilityTask.h"
#include "Navigation/PathFollowingComponent.h"
#include "AbilityTask_MoveCharacterToLocation.generated.h"
class UPathFollowingComponent;
class ADandelionPlayerController;
class UDandelionGameplayAbility;
/**
* Simple delegate for callbacks on MoveToLocation tasks.
* @param PathingResultType The result type of the pathing request.
*/
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(
FMoveToLocationSimpleDelegate,
EPathFollowingResult::Type,
PathingResultType
);
/**
* Abstract base class for moving a character to a particular world location, raising desired events on completion, and
* ending the task appropriately. Implementers need to handle setting the actual target location explicitly. Uses the
* navigation system for character movement.
*/
UCLASS(Abstract)
class DANDELION_API UAbilityTask_MoveCharacterToLocation : public UAbilityTask
{
GENERATED_BODY()
public:
/**
* Callback that is issued once the NavSystem indicates the TargetLocation has been reached.
*/
UPROPERTY(BlueprintAssignable)
FMoveToLocationSimpleDelegate OnMoveComplete;
/**
* Disables ticking.
*/
UAbilityTask_MoveCharacterToLocation();
/**
* Static constructor. Initializes cached references when called.
* @param OwningAbility The GA that initiated this task.
* @param TaskInstanceName The name of this task.
* @return A newly instantiated and initialized UAbilityTask_MoveCharacterToLocation.
*/
UFUNCTION(
BlueprintCallable,
Category = "Ability|Tasks",
meta = (HidePin = "OwningAbility", DefaultToSelf = "OwningAbility", BlueprintInternalUseOnly = "TRUE")
)
static UAbilityTask_MoveCharacterToLocation* MoveCharacterToLocation(
UDandelionGameplayAbility* OwningAbility,
const FName TaskInstanceName
);
/**
* Simple getter for the TargetLocation vector.
* @return The value of the TargetLocation vector.
*/
FVector GetTargetLocation() const;
/**
* If something other than the internal completion of this task causes it to end, stop movement immediately.
*/
virtual void ExternalCancel() override;
protected:
/**
* Cached reference to the PlayerController that possessed the Avatar Actor on the GA that initiated this task.
*/
UPROPERTY(Transient)
TObjectPtr<ADandelionPlayerController> PlayerController;
/**
* The location this task it attempting to move to.
*/
FVector TargetLocation;
/**
* Stops any currently ongoing movement and starts a new pathing request for the NavSystem. Binds
* HandleOnRequestFinished to the RequestFinished callback on the NavSystem.
*/
virtual void Activate() override;
/**
* Cleans up the delegate binding that was created in Activate.
* @param bInOwnerFinished If the TaskOwner finishing resulted in this callback.
*/
virtual void OnDestroy(bool bInOwnerFinished) override;
/**
* Helper function that acquires cached references to the PlayerController and the PathFollowingComponent.
* @param OwningAbility The GA that initiated this task.
*/
void InitializeBaseMoveTask(const UDandelionGameplayAbility* OwningAbility);
private:
/**
* Cached reference to the PathFollowingComponent on the PlayerController that possessed the Avatar Actor on the GA
* that initiated this task.
*/
UPROPERTY(Transient)
TObjectPtr<UPathFollowingComponent> PlayerPathFollowingComponent;
/**
* Cached value from when the pathing request is made to the NavSystem so that HandleOnRequestFinished can respond
* to the correct pathing request.
*/
FAIRequestID PathRequestID;
/**
* Cached delegate binding to clean up the HandleOnRequestFinished binding once this task exits.
*/
FDelegateHandle HandleOnRequestFinishedBinding;
/**
* Simple handler for OnRequestFinished callback. If the ID matches, broadcast to the GA so that it can respond
* appropriately. The owning GA needs to be in charge of ultimately shutting this task down.
* @param AIRequestID The ID for the pathing request that got completed.
* @param Result Data describing the result/outcome of the pathing request.
*/
void HandleOnRequestFinished(const FAIRequestID& AIRequestID, const FPathFollowingResult& Result) const;
};
AbilityTask_MoveCharacterToLocation.h - Snippet hosted by \"Cacher\"
");