Simple Input Handling

I don’t understand the Input system of UE4. i have a simple scene with a simple pawn. Now i want to print an “hello world” on the log panel after pressing a key. I’ve created an Action in the projectsetting called “Aleft” with an “p” key trigger. i’ve tried to use InputComponent->BindAction() in my pawnclass with no success… InputController is a NULL pointer so it crashes… then i tried to do the same thing on the playercontroller class and it’s the same… it seems that InputComponent it’s not a valid pointer… but how can i use it? and why a so simple thing is so complicated?

EDIT I now put the actionbinding inside a the SetupPlayerInputComponent method in the pawn class… i know that that method is called when the pawn is possessed (and i presume after creating the InputComponent actual object)… but the thing is that i don’t know how to posses it… because i cant let the player controller class spawn it. i spawn manually in the editor the pawn cause i’ve to modyfing it for every stage (a have to modify a member variable string that is different for every stage)

Try overwriting the SetupInputComponent in the player controller.

in your Customplayercontroller.h:

virtual void SetupInputComponent(void);

in you Customplayercontroller.cpp:


InputComponent->BindAction("Aleft", IE_Pressed, this, &Customplayercontroller::YourFunction);

You should be able to find some examples on the web. Put any code you want in YourFunction.

it dosn’t work… i’ve tried it already yesterday (just after read it on a tutorial)…

can it be pheraps because my player controller class don’t possess any pawn?

you can at least confirm that possessing of a pawn is indispensable in order to get input and executing funtion? or there is a way to manage input without possessing any pawn?

thankyou very much for your answers… i’l try to possess it and spawn manually another object for the string (that btw point a proprietary file that generate the stage itself… the file is maded with another software)

If all you are changing is a string then there are better ways to do it than putting the pawn manually in the editor. I am not familiar with possessing but it should be doable. I suggest you store the string in something other than the pawn in the level, and if you need it just get that object and cast and get the string.

As I said I am not familiar with possession, so I do not have much knowledge on that subject. My player controller is actually possessing a camera but still controlling the movement of the player, so I do not know what happens to the input without something to possess. But in my case I am using the input to control a pawn not possessed directly by the same controller that is handling input.