[bug] losing focus when clicking in level view

Hi,

In 4.12 i have the issue that when the user clicks somewhere in the dead space of my menu i lose keyboard focus and the focus is returned to the viewport. In previous versions i used the following workaround:

Basically setting the canvas to visibility true and inputmode to UIOnly, but it seems that this is not enough anymore in 4.12. While debugging i verified that MouseCaptureMode = EMouseCaptureMode::NoCapture, but it still obtains focus.

My guess is that FSceneViewport::OnFocusReceived(const FFocusEvent& InFocusEvent) should return an unhandled reply in case the input mode is no capture, but i am not able to overrule this without changing the ue4 sourcecode.

Any way to get this working without modifying the engine source?

Cheers!

Cageman

Hello cageman,

I have a few questions for you that will help narrow down what issue it is that you are experiencing.

Quick questions:

  1. Can you reproduce this issue in a clean project?
  2. If so, could you provide a detailed list of steps to reproduce this issue on our end?
  3. Could you provide screen shots of any widgets/blueprints that may be involved in this issue?
  1. Yes, just did it. If you need a repro project let me know.
  2. In the hud beginplay set input mode to UIOnly and create a widget and add it to the viewport. The widget should contain a button, the widget itself should fill the entire screen. Ensure that in the controller you set show cursor to true to show the mouse. Click on the button once to make it receive keyboard focus (to verify it does have focus you can use the focus render rule to always in interface under project settings). Afterwards click somewhere else in the window and you will notice it loses focus.
  3. I think instructions in 2. are enough, otherwise i will send the test project.

Hello cageman,

This appears to be working as intended. If I understood your issue correctly, I have an example that may be viable depending on your needs. I have provided it below. I hope that this can get you started towards a solution.

Example:

Here I have added two buttons to the designer tab, set the canvas to visible, and I have made the Canvas panel a variable.

Here I have used the OnMouseDown function to set the keyboard focus when clicking the canvas panel.

Here I have added the widget the viewport and I have set the input mode to UI Only

Make it a great day

1 Like
  1. How would this solution be viable for a lot of buttons in a widget? It would be very annoying to check them all for keyboard focus and ensure they keep focus after the click.
  2. Can you explain to me what EMouseCaptureMode::NoCapture should be doing? Looking at the code it should ensure that the mouse clicks on the viewport are ignored and i would expect also the keyboard focus would not be set due to this fact.

I understood your example and i found a decent solution. I made a blueprint exposed function that looksup the currently focused widget and sets a focus reply event. I called it keepfocushandled which returns an event reply for the mouse down event. This works fine, although this solves my mouse click issues i found thst keyboard navigation can also cause the viewport to receive focus. It would be great if you guys would show an umg example which supports keyboard, gamepad and mouse navigation.

Hello cageman,

Additional information about the workaround above. Additional buttons would not be needed. It was an example on how you could setup multiple default buttons to focus. If you just want a single button to always have focus by default you could use the following.

96584-onmouseupfocus.png

I am happy to hear that you were able to find a solution to the issue that you were having. As for the other issue that you reported in your last comment. I believe that it was filed under UE-32647. I hope that this information helps.

Make it a great day

You can put border on the backgound of your widget and make it transparent.