Handling input in AActor without blocking/consuming it

I’d like to have several Actors in my game responding to player input simultaneously while having player’s pawn respond to input too.

I’ve created an AActor class to test this functionality. It should respond to input and send it down the stack without consuming it. But for some reason input handled by this actor doesn’t get passed to pawn. If there’s a few of these actors in my level, each of them is responding to input just fine, but my pawn stops responding to this specific input whatsoever.

Steps to recreate this problem:

  1. Create new project from First Person template
  2. Create new C++ class and add code from snippet below to it
  3. Spawn few actors from this class during runtime - you’ll see that you can’t move sideways anymore

C++ code for this actor:
MyActor.h:

UCLASS()
class TESTPROJECTCPP_API AMyActor : public AActor
{
	GENERATED_BODY()
protected:
	virtual void BeginPlay() override;
public:
	void MyFun(float AxisValue);
};

MyActor.cpp:

void AMyActor::BeginPlay()
{
	Super::BeginPlay();
	
	bBlockInput = false;
	const APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
	EnableInput(PlayerController);
	InputComponent->bBlockInput = false;	//just in case
	
	FInputAxisBinding Binding = InputComponent->BindAxis(TEXT("MoveRight"), this, &AMyActor::MyFun);
	Binding.bConsumeInput = false;
}

void AMyActor::MyFun(float AxisValue)
{
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Red, TEXT("Hello world"));
	}
}

Blueprint spawning those actors during runtime:

Input stack:

211616-inputstack.png

My question is:

  • Am I doing something wrong?
  • What can I do to make input go to my actors AND my pawn?

FInputAxisBinding Binding is the problem. You’re storing binding by value, making a copy of it, then setting Binding.bConsumeInput in that copy not in a binding inside input component. You need to store Binding by reference (&)
FInputAxisBinding& Binding;
Binding.BConsumeInput = false; then this actor will not consume input.