Common UI Activatable Widget Switcher - Losing Focus Solution

Hi,

I’ve spent a lot of time messing around with Common UI and I was having an issue with the CommonActivatableWidgetSwitcher (CAWS). There’s not great documentation or support for Common UI yet so I wanted to share what I learned here to help anyone having this issue in the future…

THE ISSUE

I was using the CAWS in my UI to switch between screens (Inventory, Map, Settings etc.). However, I noticed that in some cases after switching the new widget wasn’t becoming active and for Gamepad in particular this would mean you get stuck (no way to exit, none of the buttons work). Furthermore, widgets with no buttons on them at all to focus on also cause the same issue. It’s not clear if this is a bug or intended behavior (I’m in UE5.2) but switching a widget in this way which is meant to activate the next widget seems more like a bug if it doesn’t actually activate and properly set focus.

THE SOLUTION

By default, the CAWS has a 0.4 transition duration to give a nice fade effect. This causes an issue where the new widget doesn’t always set focus. If you don’t need the transition effect, setting the transition duration to 0 will likely fix it as it correctly sets focus. This can be found in the Details panel of the CAWS.

If you want a transition duration, you can run a delay after calling the activation function (i.e. Activate Next Widget) for the same length or a little longer than the transition duration and then using Set Focus on the relevant button or object on your widget that you want to put focus on.

Lastly, activating a widget with no buttons on doesn’t seem to work with Gamepad as it has nothing to set focus too and therefore the Gamepad stops working and you get stuck on the screen with no way out without using the mouse. You can solve this by adding a button and making all of the alpha in the Tint for Normal, Hovered, Pressed, Disabled to 0. Ensure the button Is Focusable = True and Enabled = True.
If you’re seeing a blue border around your invisible button, go to Project Settings / Engine - User Interface and change ‘Render Focus Rule’ to Never and that should remove it.

I hope this is helpful for anyone having this issue.

Thanks!

10 Likes

Just wanted to pop in and say, thank you! I could not figure out what was causing my widgets to lose focus. It only happened when I spammed the back button (or a cancel button) and I was losing my mind trying to figure out why. Removing the transition 100% fixed the issue.

1 Like

Thanks a lot, I’ve been having a hard time figuring out why my buttons required a gamepad button press to get an initial focus.

Thank you very much! I wasted 3 hours on this issues!

If you want something cleaner than a delay, there is a virtual function HandleSlateActiveIndexChanged in the CommonAnimatedSwitcher code that you can override to broadcast an event whenever the widget changes so you can focus at the exact right moment (which is halfway through the duration actually I think). You might avoid some bugs that way (eg user switching again before the end of the delay).

2 Likes

What I did was set the parent widget to focusable (and override OnFocusReceieved to be properly focusable). Then in OnFocusRecieved I set the desired widget.

This seems to properly swallow and bounce back any focus changes from spamming buttons during the transition.

1 Like