Multiplayer: Getting the pawn from the player (C++)

I ended up with this solution:

 AMyCharacter *GetPlayer(int32 PlayerID)
    {
         for (auto PlayerState : PlayerArray)
    	{
    		if (PlayerState->PlayerId == PlayerID)
    		{
    			AMyPlayerState*PS = Cast<AMyPlayerState>(PlayerState);
    			if (!PS)
    				return NULL;
    
    #ifdef WITH_SERVER_CODE
    			if (Role == ROLE_Authority)
    			{
    				APlayerController *PC = PS->ParentController.Get(false);
    				if (!PC)
    					return NULL;
    				return Cast<AMyCharacter>(PC->GetPawn());
    			}
    #endif
    
    #if !UE_SERVER
    			return PS->ParentPlayer.Get(false);
    #endif
    			return NULL;
    		}
    	}
    }

(MyPlayerState.h)
public:
#ifdef WITH_SERVER_CODE
	TWeakObjectPtr<APlayerController> ParentController;
#endif

#if !UE_SERVER
	TWeakObjectPtr<class AMyCharacter> ParentPlayer;
#endif
};

(MyGameMode.cpp)
void AMyGameMode::StartNewPlayer(APlayerController* NewPlayer)
{
	Super::StartNewPlayer(NewPlayer); // Remember this, if forgotten HUD is disabled ;P

	AMyPlayerState *PS = Cast<AMyPlayerState>(NewPlayer->PlayerState);
	if (PS)
		PS->ParentController = NewPlayer;
}

(MyCharacter.cpp)
    void AMyCharacter::OnRep_PlayerState()
    {
    	Super::OnRep_PlayerState();
    
    #if !UE_SERVER
    	AMyPlayerState *PS = Cast<AMyPlayerState>(PlayerState);
    	if (PS)
    		PS->ParentPlayer = this;
    #endif
    }