I’m surprised that I am again finding something that is so simple so difficult to get working. I was hoping some basic input (Like Key X is pressed) would come as a simple structure for the engine, even part of the GEngine class or something but it seems not?
So I decided to have a dig around in the documentation and forums and found the FPS tutorial which showed me how to get a simple input working in code. However, I have tried to add this method to a previous project and I just can’t seem to get it working.
I created a character class which does some things like create some spheres and set their positions and that all seems to work, however when I press down on a key, it just doesn’t seem to register it at all.
// header file
protected:
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) OVERRIDE;
UFUNCTION(BlueprintCallable, Category = "InputControls")
void DeleteAllBalls();
// .cpp file
void AInputControls::SetupPlayerInputComponent(UInputComponent* InputComponent)
{
// set up gameplay key bindings
check(InputComponent);
if (InputComponent != NULL)
{
InputComponent->BindAction("Test", IE_Pressed, this, &AInputControls::DeleteAllBalls);
}
}
void AInputControls::DeleteAllBalls( )
{
m_ballManager->DeleteAllBalls();
}
I have setup the Action ‘Test’ in the project settings but for the life of me I can’t seem to get it to work. Am I missing something obvious that needs to be ticked to allow input or is there a more simple way to check in code if a key, for example ‘X’ has been pressed?