How to let second APlayerController use second Xbox controller input?

Rijke
Mon, 26 Oct 2015 16:03:27 +0000
Character & Animation

I have two pawns in my level, and I want each to be controlled by a different xbox controller. They both share the same camera. Right now the first pawn works fine and I setup the controls like this…

    m_pCont1 = GetWorld()->GetFirstPlayerController();
    m_pCont1->Possess(m_pPawn1);
    m_pCont1->SetViewTarget(m_pCamera);

And this will eventually call into Pawn1’s SetupPlayerInputComponent() method as expected.

To set up the second pawn, I am using this code:

    m_pCont2 = GetWorld()->SpawnActor<APlayerController>();
    GetWorld()->AddController(m_pCont2);
    m_pCont2->Possess(m_pPawn2);
    m_pCont2->SetViewTarget(m_pCamera);

But Pawn2’s SetupPlayerInputComponent() method is never called. I read from other posts that a second playercontroller should automatically receive input from a second Xbox controller.

Any suggestions would help, I think I might using the wrong code to setup a new PlayerController.

3 posts - 1 participant