Inputs / BindAction not working

Hey everyone,

I have a weird problem with Inputs. I defined an Input and I can use it in Blueprints, but I can’t use it from c++.
I don’t get an error, but the function isn’t called. It neither works with my pawn.
Here my code:

PlayerControllerRTS.h

	virtual void SetupInputComponent() override;

	UFUNCTION()
	void Build();

PlayerControllerRTS.cpp

void APlayerControllerRTS::SetupInputComponent()
{
	Super::SetupInputComponent();

	if (InputComponent) {
		InputComponent->BindAction(TEXT("Forward"), IE_Pressed, this, &APlayerControllerRTS::Build);
		UE_LOG(LogTemp, Warning, TEXT("InputComponent Exists"));
	}
}

void APlayerControllerRTS::Build()
{
	UE_LOG(LogTemp, Warning, TEXT("Build"));
}

“InputComponent Exists” gets logged, “Build” not.

Thanks in advance

1 Like

I know this sounds stupid, but do you ever “activate” (press the button bound to) your “Forward”? I am assuming it is properly setup in your project settings since you can use it in blueprints.

  1. Check that your Actor is set to receive input.

  2. Check anywhere else that this input is used to make sure it is not being consumed. If this is in bp, click on the event and uncheck “Consume Input”

Hi
Please make sure that:

  • make sure void Build(); is declared as a public method in PlayerControllerRTS.h
  • In your Project settings > Input please make sure that under Action mappings you have added a mapping called Forward
  • Make sure that your InputComponent class hasn’t been subclassed and you are using the wrong Input component class.
  • Add EnableInput(this) somewhere before if (InputComponent) in APlayerControllerRTS::SetupInputComponent() (you shouldnt need this but to be extra safe)
  • If you are still having issues here is some sample code that is tested working on 4.25 for binding input to custom player controllers:
    – Header : Unreal-cpp-boilerplate/CustomPlayerController.h at master · tanerius/Unreal-cpp-boilerplate · GitHub
    – and implementation https://github.com/tanerius/Unreal-cpp-
    boilerplate/blob/master/Source/CustomTemplate/CustomPlayerController.cpp

I hope this helps.

Hi
Please make sure that:

I hope this helps.

Hi,

  1. Don’t know how to set this

  2. I tried it without deriving, so no BP, and since it’s the PlayerController it can’t be consumed I think.

Yes I press it

Hi,

still can’t make it work

void Build() is public

I have action mappings with the right names

I added EnableInput(this) - didn’t change anything, maybe worth noting: VA gives it the color for Classes and not for functions - EDIT: UE Log says: “Error: EnableInput can only be specified on a Pawn for its Controller”

I tried copying everything I thought would be useful out of the example and didn’t work.

I copied the whole example and just changed API name and deleted the widget stuff and created inputs with the right names, still not working.

Maybe you have another idea

Update: I just want to hang myself. After hours of searching and trying it in new project i noticed that it is because i missed the “Super::PlayerTick(DeltaTime);” in my PlayerTick. I don’t know how my stuff in the tick function worked perfectly when i missed this all the time.
Also I don’t know if I should be happy now or not.

Anyways, thanks to everyone who tried to help me.

1 Like

same brother