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"

PlayerController doesn't select pawn?

So , i'm a beginner with unreal engine 4 and i'm trying to make a player controller what select a pawn with the left mouse click, but when i click on the pawn it doesn't get possessed. Also , i would like to don't make a method in the pawn itself , since i'm trying to make a rts controller, where the player can control multiple pawns , so write the method in every pawn would be annoying , also i prefer to having everything in the player controller. (sorry for my potato english) This is my code: MyPlayerController.cpp

 #include "RTSTry.h"
 #include "MyPlayerController.h"
     //Enable Mouse Cursor and Events
     bShowMouseCursor = true;
     bEnableClickEvents = true;
     bEnableMouseOverEvents = true;
     bEnableTouchEvents = true;
     bEnableTouchOverEvents = true;
     if (GEngine) {
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FString::Printf(TEXT("Controller Initialized")));
 void AMyPlayerController::SetupInputComponent() 
     InputComponent->BindAction("LeftClick", IE_Pressed, this, &AMyPlayerController::OnLeftClick);
 void AMyPlayerController::OnLeftClick()
     FHitResult hit;
     GetHitResultUnderCursor(ECC_Pawn, false, hit);
     if (hit.bBlockingHit) {
         if (hit.Actor != NULL) {
             APawn* selectPawn = Cast<APawn>(hit.GetActor());


 #pragma once
 #include "GameFramework/PlayerController.h"
 #include "MyPlayerController.generated.h"
 class RTSTRY_API AMyPlayerController : public APlayerController
     void OnLeftClick();
     virtual void SetupInputComponent() override;
Product Version: UE 4.15
more ▼

asked Apr 19 '17 at 07:40 PM in C++ Programming

avatar image

3 2 4

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

1 answer: sort voted first

I will list some items that you can check, perhaps they will solve your issue:

  • Make sure that there is really an action called "LeftClick"

  • hit.Actor can be NULL, while hit.Component is valid. You can check this and then receive the actor with hit.Component->GetAttachmentRootActor()

  • You should check if the casted pawn is != NULL

  • Make sure your pawns really use the collision channel ECC_Pawn

more ▼

answered Apr 19 '17 at 08:42 PM

avatar image

831 21 4 29

avatar image Ale1221 Apr 21 '17 at 07:12 PM

Thanks , i had to change ECC_PAWN Collision setting in Project Setting , now it works.

(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