ManlyMarco / RuntimeUnityEditor

In-game inspector and debugging tools for applications made with Unity3D game engine
GNU General Public License v3.0
802 stars 98 forks source link

Suggestion: Block Rewired input during typing #17

Closed benediktwerner closed 3 years ago

benediktwerner commented 3 years ago

It's pretty annoying when typing in the REPL and suddenly all kinds of things are happening in the background because the game also responds to the inputs. Unfortunately, it doesn't seem like there is a general way to prevent this in Unity but at least it should be possible to do for games using Rewired (any maybe also other input systems).

I'd be up to implement something like this but I wanted to ask first if that sounds like a good idea and it's something you would accept.

The only issue I can see is that it might not be that easy to determine when a user is focused in a text field so maybe an alternative in that case would be a button/toggle to disable all game input.

benediktwerner commented 3 years ago

Actually, it seems that in games not using Rewired the keyboard input is blocked correctly anyways, so this seems to be a Rewired specific issue.

ManlyMarco commented 3 years ago

The input blocking is the same as used in BepInEx.ConfigurationManager, so the fix would also be the same. It's weird that the inputs go through since they should be cleared every frame, that framework must be doing something unusual with how it gets the keys. It might be easier to make a separate plugin/script that patches rewired to not do that. Maybe disable its inputs if mouse cursor is over an IMGUI window.

benediktwerner commented 3 years ago

I don't think BepInEx.ConfigurationManager or this plugin are doing any additional input blocking, or are they? But Rewired is definitely doing some special stuff that causes it to not get blocked. I believe Unity by default already disables the normal input methods when a textbox is focused. This blocking by Unity was probably also the main issue why BepInEx/BepInEx.ConfigurationManager#10 was necessary and the existing code didn't work already. Or was this caused by some extra blocking done by the plugin?

In any case, I guess blocking Rewired would require some nasty reflection or a dependency on it in some form which indeed doesn't sound ideal. I now just created a simple Plugin which disables Rewired's keyboard input when Unity reports a UI element has keyboard control: https://github.com/benediktwerner/RewiredBlocker

ManlyMarco commented 3 years ago

Both of these plugins call Input.ResetInputAxes every frame when mouse cursor is over their windows. Config manager also places an extra ongui window underneath to catch stray clicks. Rewired is the only case where this is not enough that I've seen so far.