Where do I handle the input for a PlayerController?

I started of with the ThirdPerson template and all inputs are handled in the Character class under SetupPlayerInputComponent

Is this the place where all of my inputs should be handled? What if I want to change some variable in the PlayerController based on some inputs?

I can’t access the the PlayerController from a Character because it is just a Controller. I also tried to bind some inputs in the PlayerController itself like this

void AThirdPersonController::ToggleMouse(){

	this->bShowMouseCursor = !bShowMouseCursor;
void AThirdPersonController::SetupInputComponent(){
	if (InputComponent != NULL)
	InputComponent->BindAction("RightMouse", IE_Pressed, this, &AThirdPersonController::ToggleMouse);

but this gives me a runtime error.

How would I do this?

I think I can answer my own question.

Handle all input in the Character class and cast the controller to a playercontroller with CastToPlayerController or CheckedCast

I think as long as you have the 1-1 relationship between controller and actor you can do it this way. But let’s think about an 1-n relationship where a controller controls an camera-actor and can also select n other actors which may represents units in a RTS Game.

I see two possible solutions: Handle the input in the PlayerController or handle the input in the pawn. My first solution would handle the input in the controller but store properties like selected actors in the pawn.

But maybe there are other suggestions and experiences?

I was also trying to get the PlayerController to handle the input. I figured that would be the best place to process inputs that were not specific to a Character, but I was having the same problems with a runtime error in SetupInputComponent. I think that the issue is that InputComponent is not automatically initialized to anything, you have to create a UInputComponent object for it. I found some sample code in the Pawn class, that I suspect might be getting called by the engine to generate the InputComponent that is passed into the Character’s SetupPlayerInputComponent. I initialized the InputComponent pointer like this:

static const FName InputComponentName(TEXT("TravelInputComponent0"));
InputComponent =  ConstructObject<UInputComponent>(UInputComponent::StaticClass(), this, InputComponentName);

I am still pretty new to Unreal 4, and am uncertain if this is the right thing to do here. It seems to work, however.

I think we’re researching on similar topics. I have been unable to find a best path for implementing a player controller input. One requirement on mine is that the input needs to handle absolute coordinates and translate those to the PlayerController. Though this sounds simple, in theory, I haven’t been able to find a suitable answer yet.

Here’s a link to my posted question.

Remember to call super in your SetupInputComponent(). This fixed the BAD_ACCESS error I was getting. Good luck!