Switching widgets without using Widget Switcher

Hello!

I have a little trouble switching widgets but without using widget switcher.
At first, the widget switcher was very useful and effective but as the inner logic gets more and more complex, it seemed better to create separated widgets and switch them(call them) when needed.

I created a mode change button from each widgets(there are two widgets) and on click event, linked ‘Remove from Parent’ node and created the other widget, added to viewport.
However, it’s not properly working because on initialization, first widget is created from Level Blueprint but when I try to remove a widget, the logic is declared in a widget itself.

Is there any simple way to switch two independent widgets without using Widget Switcher?

  1. First widget blueprint

  2. Second widget blueprint

  3. Level blueprint

Look into gameplay tags. They are like hierarchical enumerators, with search , compare, switch on etc functions.

To decide which screen to display make function that determines and sets correct tag like: screen.hud, screen.settings, screen.gameover etc.

Then make dispatcher, that fires every time you changed what should be displayed.

Hook widget switcher to that dispatcher (and everything else that should know it), and switch to desired screen (use switch of gameplay tag).

Then do similar gameplay tags for buttons names, like button.exit, button.apply. And button states: button.hoovered, button.pressed. Now time for next dispatcher: with button name, and what happened to button.

This way you can have all ui code in single blueprint, without running to problem: “this same code is in 20 buttons, just different references”

1 Like

Hello! If your screenshots are up to date, it seems that you have not connected the output from the “Create Widget” nodes to the input of the “Add To Viewport” nodes, just the way you are doing it in the level blueprint.

If the input node of the “Add to viewport” nodes remains empty, it will try to add itself, but actually you want to remove that same widget and add the new one you created. Connecting the return value of Create Widget to the input of Add To Viewport should work in that case.

1 Like

Hi! Sorry for the late reply…

The widget didn’t switch since the essential nodes (especially the targets) were not connected, just like @NLaurito found out.
Thank you for the help!

In case of dispatcher, it was hard for me to get a concept of it but still, thank you for the advice @Nawrot !

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.