segross / UnrealImGui

Unreal plug-in that integrates Dear ImGui framework into Unreal Engine 4.
MIT License
666 stars 211 forks source link

Input stops working if mouse sharing is enabled and I click outside of any window #49

Closed irajsb closed 3 years ago

irajsb commented 3 years ago

looks like when an unhandled event is returned input stops working steps to reproduce:

irajsb commented 3 years ago

update : IMGUI_WIDGET_LOG(Warning, TEXT("ImGui Widget %d - Visibility updated to '%s'."), visibility gets changed toVisibility updated to 'HitTestInvisible'. but for some reason its not getting back to visible . Also there is a focus lost happening !

irajsb commented 3 years ago

Update : input gets disabled when user clicks on viewport!

segross commented 3 years ago

Hey. Unless I'm missing something, what you described is intentional behavior: https://github.com/segross/UnrealImGui#sharing-input. The whole idea of mouse sharing was to keep the mouse as long as you need it and pass it back after clicking outside of the ImGui area. If ImGui didn't yield, the game view-port would not be able to get the mouse back. Changing visibility to HitTestInvisible is correct in this case and happens when you toggle input or between "shared"/"non-shared" mouse (edit: I had to check the code to remind myself). I'll keep it open for a few days, in case you have any questions but from what you've described it sounds that it works as intended.

irajsb commented 3 years ago

Thanks for info! looks like I've to toggle back input whenever input handling outside of plugin code is finished

segross commented 3 years ago

If you want to experiment with this, I can point you to relevant bits of code @irajsb. If you find a better way to share the mouse, you can always propose it here.

It was a while back, and I don't fully remember what was the issue, but there was something that didn't quite work when trying to share the mouse. If I remember correctly, I had to make the widget hit-test-invisible and track the cursor differently (no mouse move events), but at some point, I had to give parts of the input back to the view-port, so it could handle events (unconsumed reply was not enough). An easy way was to toggle the input, but depending on the use case, there might be better way to do this. I never fully committed to that use case anyway, as I use ImGui for debugging and I want it as isolated from the game as possible - which is why I prefer toggling rather than using some mixed modes. When I have more time (someday in the future), I'd want to refactor it in a way that would allow people to create their own widgets. Until then, customizing ImGuiWidget is your best shot. And as I said, you can give me a shout and I can maybe point you to the relevant bits of code.

benui-dev commented 2 years ago

I am having a similar issue, I would really appreciate some feedback or help.

We have a mouse-based game and actions bound to left mouse click and using the position of the cursor in the window. If I enable input sharing in ImGui, and use the debug cheat to enable input in ImGui, I can drag around windows and they accept input. However as soon as I click outside an ImGui window, input for ImGui is disabled and I have to manually re-enable ImGui input to get it to respond to clicks again.

Is there a way that I can get inputs to be correctly shared? I want clicks outside ImGui windows to go to the game as normal, and clicks inside ImGui windows to be handled by ImGui...