Attaching function calls to Slate events
While creating buttons is all well and fine, at the moment, any UI element you add to the player's screen just sits there without anything happening even if a user clicks on it. We don't have any event handlers attached to the Slate elements at the moment, so events such as mouse clicks don't actually cause anything to happen.
Getting ready
This recipe shows you how to attach functions to these events so that we can run custom code when they occur.
How to do it...
- Create a new
GameMode
subclass calledAClickEventGameMode
. - Add the following
private
members to the class:private: TSharedPtr<SVerticalBox> Widget; TSharedPtr<STextBlock> ButtonLabel;
- Add the following
public
functions, noting the override forBeginPlay() ...
Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.