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"


AMyPlayerController::AMyPlayerController()
{

	//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() 
{
	Super::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());
			Possess(selectPawn);

		}
	}



}

MyPlayerController.h

#pragma once

#include "GameFramework/PlayerController.h"
#include "MyPlayerController.generated.h"

/**
 * 
 */
UCLASS()
class RTSTRY_API AMyPlayerController : public APlayerController
{
	GENERATED_BODY()


		AMyPlayerController();
	void OnLeftClick();
	virtual void SetupInputComponent() override;
	
};

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

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