I’m having an issue with widgets. Essentially, I have WidgetBlueprint1 which has a timer counting down, among other variables, and a button that opens WidgetBlueprint2.
My problem occurs when I click the button to open WidgetBlueprint2. When I do this, everything from WidgetBlueprint1, like my variables and my timer reset to their default values. I want the variables and timer to continue running in the background as I open the other Widget so that I can come back to them later.
Is there a way to do this? Or do I need to use a system other than the multiple WidgetBlueprint system I’m doing to achieve something like this?
Yes! Here you go. So the two WidgetBlueprints are called Map_Screen and Home_Screen.
They each have a button that switches to the other which is called from the Player blueprint.
So the issue is that you’re creating a new instance of the widgets when you call the open widget function, hence the default values.
Only create the widgets once, store them in variables like you do here. Then you can use those variables to show and hide the widgets.
So to fix this :
One thing to note is that using Get All Actors of Class is not preferred usually, so instead you can create a variable to reference the player in both the widgets and set them to Instance Editable and Exposed on Spawn. This is so that we can keep a reference to the player in the widget and get access to the other widget.
In your player, create the widgets, store them and hide them at the start. The Exposed variables will show up in the Create Widget node, you can connect a self node to them like so : [EDIT] Don’t forgot to add the Widgets to the Player Screen / Viewport. I forgot to do that in the screenshot!