Hello!
I’m experienced C++ programmer but absolute beginner in UE4. First of all, I have UE4 4.20.3 built from source code on Linux and got UE4Editor running. I can create some object in С++ class that derived from AActor base class - it’s moving on scene and represented as sphere on it (any other object also possible).
Is there any way to add reaction on key press? Reaction should call some C++ function in my code.
My assumption is to add some another class into scene that will catch my keypress events, and event handlers will iterate over my AActor classes and call some methods in them.
Please, could you give me some hints on how to implement that? Just link or even name of base class that best suited for this purpose?
If you need to handle keystrokes, then it is better to use Pawn and classes inherited from it, for example, Character. And set the instance optionn Input -> Auto Recevie Input -> Player 0 (Details Panel) and process the input in BP or C ++. An example can be found in First Person or Third Person Template C ++
If you want to process input in a class derived from AActor, then you need to add an InputComponent
.h file
Thank you for the reply!
Topic solved, I did everything what I wanted to.
To be honest, I found similar example code earlier but it was lacked of EnableInput(GetWorld()->GetFirstPlayerController()) call, or may be this call were placed elsewhere… Without GetFirstPlayerController call my game dynamic library caused UE4Editor to crash every time my project attempted to open without any details displayed, until I realized to delete Binaries folder and remove newly added code.
Since I have multiple objects that want to control with different keys on keyboard,