How to catch mouse event in C++

Hi all !

I was creating a C++ player controller, and I wondered which function is used to catch mouse events like “left click pressed” of "left click released.
At the end, I just want to call a c++ function when an event is catched.


Hi Daestra!

See this doc section for basic information how configuring input. In docs is used pawn, but the same way you can configure your player controller through SetupInputComponent() method. More about input and priority stack for input handling by InputComponents you can read here.

If you want catch events through components delegates you can handling OnClicked and OnReleased events.
More examples you can find in default project templates in editor.


Done it !

Simple, we can do it as a normal input like :

bEnableClickEvents = true;
bShowMouseCursor = true;
InputComponent->BindAction("MouseLeftClicked", IE_Pressed, this, &MyPlayerControler::MyFunction);

Then bind it in Settings → Project Settings → Inputs. Create a new action named “MyFunction” and chose the associated event.

Thank you.