Widget Blueprints allow game developers to use Buttons, sliders, textboxes, lists, and a whole lot more. In this example, we’ve created a widget named “simpleButton” (we should have called it simpleHUD) which contains a full HUD with a variety of UMG widgets displayed to the user when the level starts.
Within that widget, you can see that we’ve laid out a range of buttons, checkboxes, sliders, images, and text widgets, each with descriptive names like Button_test, CheckBox_test, Slider_test, editText, and so on.
We can now actuate and press buttons, drag sliders, and do other things with the Gamedriver API. From within a project that contains the gdio.unreal_api you can now reference the UMG widgets using HPath, almost the same way as you do with in-game objects.
To reference the UMG elements directly, use their name. /Button_test, in our example, is a reference to our UButton. If you have multiple instances of a widget, you could use the fully qualified name that references the object, then the element, as follows:
Now, button clicking is as simple as:
api.MouseMoveToObject("/Button_test", 20); // move mouse over button api.Wait(500); //wait ½ second api.ClickObject(MouseButtons.LEFT, "/Button_test", 20); //click
You can change editable text fields as follows:
Drag operations are useful for widgets like sliders. To do a drag on a slider we first determine the drag’s starting screen position (GetObjectPosition of the slider works). We then add an offset to create a drag using api.MouseDrag.
Vector3 sliderPosition = api.GetObjectPosition("/simpleButton_C_0/Slider_test"); api.MouseDrag(MouseButtons.LEFT, new Vector2(sliderPosition.x + 150, sliderPosition.y + 150), 500, new Vector2(sliderPosition.x, sliderPosition.y));
Since every reflected method is available on the UMG widgets, there is a lot of Unreal functionality exposed to you because api.CallMethod allows you to call any reflected method of an object! For instance, to get a button’s visibility you simply use api.CallMethod, with the HierarchyPath, “GetVisibility”, null for parameters, and get an int32 returned (you can look up the Unreal enums to see what the values represent).
int32 visibility = api.CallMethod<Int32>("/Button_test", "GetVisibility", null);
Similarly, you can access the value of a checkbox or slider as follows:
bool isChecked = api.CallMethod<bool>("/CheckBox_test", "IsChecked", null); float sliderValue = api.CallMethod<float>("/Slider_test", "GetValue", null);
Hopefully, these small examples help you get started. If you have more questions please contact our support team!