When using the Unreal Motion Graphics (UMG) toolkit, you will find that mouse events are very easy to handle. We can register C++ functions to run after mouse clicks or other types of interactions with the UMG components.
Usually, event registration will be via Blueprints; but in this recipe, we will outline how to write and wire-up C++ functions to UMG events.
Create a UMG canvas in your UE4 project. From there, we'll register event handlers for the OnClicked
, OnPressed
, and OnReleased
events.
Right-click in your Content Browser (or click on Add New), and select User Interface | Widget Blueprint, as shown in the following screenshot. This will add an editable widget blueprint to your project.
Double-click on your Widget Blueprint to edit it.
Add a button to the interface by dragging it from the palette on the left.
Scroll down the Details panel for your button until you find the Events subsection.
Click on the + icon beside any event that you...