UI buttons become inactive after clicking world

Can you show the logic where you switch the Input Mode between Game Only and Game And UI?

Whenever I change that, I usually also change a variable on the player controller.
Get Player Controller → Set Show Mouse cursor (true / false)

I’m too lazy to screenshot, so look at this thread: Show mouse cursor in BP?