InputComponent and Actors

So recently I have been working on some code and I did the same type of setup in two places and I get different results. This is in regards to binding input events for actors in C++. So, in BeginPlay I do the following:


void APaddle::BeginPlay(){
	Super::BeginPlay();
	APlayerController* PlayerController = Cast<APlayerController>(GetWorld()->GetFirstPlayerController()->GetPawn()->GetController());

	if (PlayerController){
		EnableInput(PlayerController);

		switch (PaddleType){
		case EPaddleType::PADDLE_LEFT:
			InputComponent->BindAction("SlapLeft", IE_Pressed, this, &APaddle::OnSlap);
			InputComponent->BindAction("SlapLeft", IE_Released, this, &APaddle::OnSlapRelease);
			break;

		case EPaddleType::PADDLE_RIGHT:
			InputComponent->BindAction("SlapRight", IE_Pressed, this, &APaddle::OnSlap);
			InputComponent->BindAction("SlapRight", IE_Released, this, &APaddle::OnSlapRelease);
			break;
		}

		InputComponent->BindTouch(EInputEvent::IE_Pressed, this, &APaddle::OnSlapTouch);
		InputComponent->BindTouch(EInputEvent::IE_Released, this, &APaddle::OnSlapTouchRelease);
	}
}

Now when I did something like this in the TopDown C++ code template, it worked perfectly, no issues. Now in a Blank project with minimal C++ setup, it does not work and I have to trigger the event in Blueprints. Not a huge deal, but it is not working as designed. is the DefaultInput.ini file:


[/Script/Engine.InputSettings]
DefaultTouchInterface=

!ActionMappings=Empty

+ActionMappings=(ActionName="SlapLeft", Key=A)
+ActionMappings=(ActionName="SlapRight", Key=D)

My question is, what am I doing wrong that the event is not being registered/triggered upon input?

Hey am not exacely sure what you are trying to do.
Setting up input bindings on a Actor?

Anyways am prety sure the bindings should be made in


/* Allows us to set up custom input bindings. */
	virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent);

As far as i know only APawn:: and ACharacter:: have that method.

According to the docs, an Actor can be pushed onto the input stack. And the SetupPlayerInputComponent(class UInputComponent* InputComponent) method is only called when possessed by a PlayerController, according to the docs.

Reference: https://docs.unrealengine.com/latest/INT/Programming/Gameplay/Framework/Input/index.html#inputprocessingprocedure

Long story short I want to make some objects that do not require to be possessed to listen to input events.

First, just to handle my programmer obsessiveness:


APlayerController* PlayerController = Cast<APlayerController>(GetWorld()->GetFirstPlayerController()->GetPawn()->GetController());

Is an awful lot more work than is needed.


APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();

Is identical functionality. Controller->GetPawn()->GetController() is just going to be Controller.

Ok … sorry. Now back on topic. In general your setup looks sound. When you’re in game you can also do a console command “showdebug input” which will display the current input stack. The most common cause of something like this would be that something else is consuming the key press before it makes it to your Actor.

The second idea is that the BeginPlay on the Paddle is somehow happening before APlayerController::InitInputSystem is getting called and so the input stack is getting cleared. If you have full code you could put a breakpoint at the point you push your component on to the stack and inside InitInputSystem and be sure it isn’t getting called in an unfortunate order.

Thanks for the suggestion. I will look into it when I can get back to that project and post on what was happening for anybody else who might run into this issue.

In a reply I said I would give your suggestion a whirl. It seems to only be an issue with action bindings. Axis bindings work fine. I came across the same issue in a new project as well. During debug breaks I can see that the size of objects on the stack is 4 for my action bindings (2 actions each of 2 objects). But showing input debug displays only 3 objects on the stack, missing my 2 actors and/or pawns.