Accessing Widgets
Very few times you will create a widget and not deal with it ever again. With all likelihood, you will have to access many widgets at a later point in time over the course of the game, and manipulate it (change properties, destroy it, etc.).
By far, the easiest way to access a widget is using its string ID and convenience functions. All functions starting with ui_ are convenience functions designed to help you easily interact with the system. This page will review the two most important ones.
Getting a widget by ID
You can get any widget with ui_get(). This function is not a method of the widget constructor nor any other constructor - it is a globally accessible convenience function.
For example, say we want to hide an existing panel (for example, a pause menu). Whenever it's time, we can refer to it by its string ID (say, for example, HelloWorld_Panel) and do the following:
Remember that gooey supports method chaining, so we can alternatively directly call:
A previous way to do it
Prior to gooey 2024.12, these functions were not available, and you would directly access the UI manager object and its methods to perform the same tasks. This is strongly discouraged now, as the convenience functions make sure the manager object is created before accessing it, making them safe to use automatically. Always use the convenience functions instead of directly accessing the object.
Checking if a widget exists
In the example above, if for some reason we have destroyed the panel, running that code will crash the game. To make sure this does not happen, we can first check if the widget exists. We can do that with the ui_exists() convenience function:
Wrapping up
Let's now take a look at some commonly used methods available for the UIWidget constructor - this is, methods you can use no matter which widget you're working with.