Having problems with UNavigationSystem::SimpleMoveToLocation

Hello all, I am playing around with RTS style unit selection and movement and having issues getting the SimpleMoveToLocation working in C++. Here’s my simple right mouse click input handler:

void ARtsPlayerController::SelectedObjectsActionReleased()
{
	if (SelectedActors.Num() == 0)
	{
		return;
	}

	int32 Index = 0;
	for (const auto& itrActor : SelectedActors)
	{
		FHitResult HitResult;
		GetHitResultUnderCursor(ECollisionChannel::ECC_Visibility, true, HitResult);
		FVector MoveLocation = HitResult.Location + FVector(Index / 2 * 100, Index % 2 * 100, 0);

		UNavigationSystemBase * NavSystem = GetWorld()->GetNavigationSystem();
		if (NavSystem != nullptr)
		{

			AController * Controller = itrActor->GetController();
			UE_LOG(LogTemp, Warning, TEXT("Controller: %s"), *Controller->GetName())
			UNavigationSystem::SimpleMoveToLocation(itrActor->GetController(), MoveLocation);

			DrawDebugSphere(GetWorld(), MoveLocation, 25, 10, FColor::Red, false, 3);
		}
		else
		{
			UE_LOG(LogTemp, Warning, TEXT("ERROR: *** No navigation system ***"))
		}

		Index++;
	}
}

The debughelper sphere is drawn and I see no message that the nav system is not in place. I do have a NavMesh in my map. Oddly, I have a BP derived from the Character C++ class and will respond successfully to a right click mouse button event in BP, attached image.

I would be most grateful for any insight / advice.

Thanks.

A little more digging revealed the solution.

  1. UNavigationSystem::SimpleMoveToLocation is marked deprecated in the API https://api.unrealengine.com/INT/API/Runtime/Engine/AI/UNavigationSystem/SimpleMoveToLocation/index.html

  2. Use of the UAIBlieprintHelperLibrary::SimpleMoveToLocation solved the issue but you will need to include AIModule in the C++ dependencies, update your ProjectName.Build.cs

    PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "AIModule" });
    

Hope this helps others in the future.