Not sure i understand your problem but in a effort to help.
If you have done the trace and it returns the Pawn/ Character get the controller of the pawn.
In the Player State of the controller is the member UniqueId and PlayerId.
No real documentation as such i’m afraid, i was just going by the comments from people in #unrealengine IRC channel.
So 's the current state of my initial function for getting a target:
void ASmashyPlayerController::GetPlayerTarget()
{
//cast our own player pawn for reference.
ASmashyPlayerState* Player = Cast<ASmashyPlayerState>(PlayerState);
ASmashyCharacter* PlayerPawn = Cast<ASmashyCharacter>(Player);
//deselect anything already selected.
PlayerPawn->Deselect();
//Trace to see if anything is behind the mouse cursor
FHitResult Hit;
GetHitResultUnderCursor(ECC_Pawn, false, Hit);
if (Hit.bBlockingHit)
{
//it is a player, check what team they're on.
ASmashyCharacter* TestPawn = Cast<ASmashyCharacter>(Hit.GetActor()); /// works until this point.
AController* TestPlayer = TestPawn->GetController();
//select player as enemy target
PlayerPawn->SelectPlayer(TestPlayer);
}
}
Maybe i’m doing this wrong, i was under the assumption that this:
GetHitResultUnderCursor(ECC_Pawn, false, Hit);
would run a line trace for what is clicked under my cursor, and will check to see if it was a pawn. however the game breaks and TestPawn = NULL. any ideas?
You are correct about the ECC_Pawn, it can get both actors and ground location.
Try checking if your Hit found an actor before casting, this will make sure its not a failed cast.