How to do: ACharacter::OnSimpleMoveToLocationEnd possessed by APlayerController?

Hi,

In my Top-Down ARPG, my main ACharacter-subclass receives input through a APlayerController-subclass and moves from A to B through point-and-click using UAIBlueprintHelperLibrary::SimpleMoveToLocation(PlayerController, Location). I’d like to implement a ACharacter::OnSimpleMoveToLocationEnd to achieve:

  1. Left-Mouse-Click on item
  2. Go to item
  3. Pickup item.

My approach is:

// ATheCharacter.cpp

// TheCharacter::TheCharacter() { ...
AAIController* Controller = Cast<AAIController>(GetController());
UPathFollowingComponent* PathFollowingComponent = Controller->GetPathFollowingComponent();
// TheCharacter::BeginPlay() { ...
PathFollowingComponent->OnRequestFinished.AddUObject(this, &ATheCharacter::OnMoveCompleted);

// ATheCharacter.h
private:
void OnMoveCompleted(FAIRequestID RequestID, const FPathFollowingResult& Result);

However, as expected AAIController* Controller = Cast<AAIController>(GetController()); this returns a nullptr, because my ACharacter is obviously controlled by an APlayerController.

I don’t understand why it is possible to use UAIBlueprintHelperLibrary::SimpleMoveToLocation(PlayerController, Location) with a non-AI APlayerController.

My question is, how do I implement a ACharacter::OnSimpleMoveToLocationEnd properly?

Thanks in advance!

Hello @DevKaiUnreal , from what you wrote, i suposse you want to recive a notification when the movement is completed. I think this thread will be usefull, the idea of the solution is to use a PlayerController and a AIController. The PlayerController listen to the input and send instructions to the AIController, and the AIController control your character. Other threads that may be helpfull are this and this .

I hope this is usefull (also, UAIBlueprintHelperLibrary::SimpleMoveToLocation recive a AController and a vector, and both, APlayerController and AAIController, inherit from AController, probably that is why the method can work with non-AI controller).

1 Like

Hey,

I’d just have been 1 month on vacations. Thank you for your answer. I already implemented it the way you describes it and it works. Even though I think this is more kind of a workaround and not the most elegant technique Unreal Engine offers.