x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

alt text

I would be most grateful for any insight / advice.

Thanks.

Product Version: UE 4.21
Tags:
simplemoveto.png (387.0 kB)
more ▼

asked Apr 07 '19 at 07:23 AM in C++ Programming

avatar image

CBamford
1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Apr 07 '19 at 09:22 AM

avatar image

CBamford
1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question