document.write("
// Fill out your copyright notice in the Description page of Project Settings. UAbilityTask_MoveCharacterToLocation::UAbilityTask_MoveCharacterToLocation() { bTickingTask = false; } UAbilityTask_MoveCharacterToLocation* UAbilityTask_MoveCharacterToLocation::MoveCharacterToLocation( UDandelionGameplayAbility* OwningAbility, const FName TaskInstanceName ) { UAbilityTask_MoveCharacterToLocation* NewTaskInstance = NewAbilityTask<UAbilityTask_MoveCharacterToLocation>(OwningAbility, TaskInstanceName); NewTaskInstance->InitializeBaseMoveTask(OwningAbility); return NewTaskInstance; } FVector UAbilityTask_MoveCharacterToLocation::GetTargetLocation() const { return TargetLocation; } void UAbilityTask_MoveCharacterToLocation::ExternalCancel() { if (IsValid(PlayerController)) { PlayerController->StopMovement(); } Super::ExternalCancel(); } void UAbilityTask_MoveCharacterToLocation::Activate() { if (!IsValid(PlayerController) || !IsValid(PlayerPathFollowingComponent)) { UE_LOG( LogGameplayTasks, Warning, TEXT("%s: Tried to Activate with an invalid avatar PlayerController or PathFollowingComponent."), *GetFullNameSafe(this) ) return; } PlayerController->StopMovement(); UAIBlueprintHelperLibrary::SimpleMoveToLocation(PlayerController, TargetLocation); PathRequestID = PlayerPathFollowingComponent->GetCurrentRequestId(); HandleOnRequestFinishedBinding = PlayerPathFollowingComponent->OnRequestFinished.AddWeakLambda( this, [this](const FAIRequestID& AIRequestID, const FPathFollowingResult& Result) { HandleOnRequestFinished(AIRequestID, Result); } ); Super::Activate(); } void UAbilityTask_MoveCharacterToLocation::OnDestroy(const bool bInOwnerFinished) { if (!IsValid(PlayerPathFollowingComponent)) { UE_LOG( LogGameplayTasks, Verbose, TEXT( "%s: Attempting OnDestroy with an invalid PlayerPathFollowingComponent. May result in a loose delegate." ), *GetFullNameSafe(this) ) Super::OnDestroy(bInOwnerFinished); return; } if (HandleOnRequestFinishedBinding.IsValid() && PlayerPathFollowingComponent->OnRequestFinished.IsBound()) { PlayerPathFollowingComponent->OnRequestFinished.Remove(HandleOnRequestFinishedBinding); } Super::OnDestroy(bInOwnerFinished); } void UAbilityTask_MoveCharacterToLocation::InitializeBaseMoveTask( const UDandelionGameplayAbility* OwningAbility ) { this->TargetLocation = FVector::ZeroVector; const APawn* AvatarPawn = OwningAbility->TryCastAvatarActorFromActorInfo<APawn>(); if (!ensure(IsValid(AvatarPawn))) { UE_LOG( LogGameplayTasks, Error, TEXT("%s: Tried to instantiate a new MoveToCursorTask without a valid avatar Pawn."), *GetFullNameSafe(this) ) return; } ADandelionPlayerController* AvatarController = AvatarPawn->GetController<ADandelionPlayerController>(); if (!ensure(IsValid(AvatarController))) { UE_LOG( LogGameplayTasks, Error, TEXT("%s: Tried to instantiate a new MoveTo task without a valid avatar PlayerController."), *GetFullNameSafe(this) ) return; } this->PlayerController = AvatarController; UPathFollowingComponent* AvatarPathFollowingComponent = AvatarController->GetPathFollowingComponent(); if (!ensure(IsValid(AvatarPathFollowingComponent))) { UE_LOG( LogGameplayTasks, Error, TEXT( "%s: Tried to instantiate a new MoveTo task without a valid PathFollowingComponent on avatar PlayerController: %s." ), *GetFullNameSafe(this), *GetFullNameSafe(AvatarController) ) return; } this->PlayerPathFollowingComponent = AvatarPathFollowingComponent; } void UAbilityTask_MoveCharacterToLocation::HandleOnRequestFinished( const FAIRequestID& AIRequestID, const FPathFollowingResult& Result ) const { if (AIRequestID != PathRequestID || !Result.IsSuccess()) { return; } OnMoveComplete.Broadcast(Result.Code); }