I am wondering if anybody can help me keep my UMG the same after it closes. Basically what what happens is after a button is pressed it’s visibility changes (nice and easy), but when I change to another UMG and then reopen the UMG that holds the button, the visibility is reset to its default state. As this is a sort of turn based game I will need the button to change back to default (visible) after the player ends their turn but stay invisible when they press it within their turn.
Sorry if this all sounds a bit jumbled, I couldn’t find a better way to word it.
UMG is for displaying the data and user input. Esp small things like buttons. You need to move LOGIC of your interface elsewhere.
Create MASTER widget that is just container for all subpages of your gui. Then create each page (view or mode of gui) as separate widget (ie make them as custom widgets). Then in construct time of MASTER widget get reference to self (ie master widget) and set it in all child, subwidgets. This way each subwidget can get variables from master widget. Then in master widget place all gui logic, and because its always visible and always running, it will never forget. You can add custom widgets just like they were normal simple gui items.
Short version: create master widget and subpages for every gui state (as custom widgets), then keep all gui logic in master widget.
While I agree with keeping as much logic away from the umg as possible, as personal preference more than any real practical reasons, There’s really no reason why you should run into the issue you are if you are doing things correctly. What I’m saying is that there’s probably something you’re missing.
If you open a widget, press a button that sets its visibility to collapsed, close the widget and reopen the widget, the button should stay collapsed.
So what’s going wrong? Right now there’s two things I can think of:
Often when people post about umg issues and they post their blueprint setup, it turns out that every time they “open the widget”, they actually create the widget, thus opening the newly created widget, which of course has the default look.
Every time you “open a widget” (as in adding it to viewport) the construction event executes. Do you have any logic that runs during the construction?
In case you, or anyone else, wonders how to get around that, I usually put a Sequence node after the construction, followed by a Do Once after the 0 pin. Now, 0 will execute only once no matter how many times you open or close the widget and 1 pin will execute every time.
The above answers are good answers. However, another solution (because options are always nice) would be to use a widget switcher. The way it works is that it holds multiple widgets but can cycle through them (showing one at a time). You could think of this kind of like your web browser, how when you click different tabs it will show different pages in the same window. I hope that this information helps.
Here you can see that I added a widget switcher to my designer tab. I have placed two images in it (Blue and white). I have also added a button that I will use to flipflop between to two images.
In this blueprint it switches the active widget (The widget being shown) back and forth between the blue image and the white image. These images can be replaced with what ever widgets you are using. It can also hold more than just two widgets. This means that you will be able to switch between what ever widgets you need.