This might be a GUI problem but my situation involves a lot of moving parts, so I'm going to ask generally to be sure. Basically, it amounts to this: keyboard and mouse event propagation gets wacky when you wrap a Viewport in a ViewportContainer within a UI. I'm trying to make an in-game map editor with a TileMap wrapped in a GUI like so:
Control
- Container (some buttons here)
- FileDialog (opens and saves a file)
- ViewportContainer
And ViewportContainer's children
- TileMap <- where the trouble script is
- Camera
When the FileDialog is open, a script on my TileMap gets ALL events on _input, instead of them getting blocked on the way down. The FileDialog is exclusive and set to STOP for its filter, so this is weird to me. Mouse and keyboard both bleed through.
Using unhandled_input causes key release events to still trigger, but not presses (ooookay). It also catches mouse events. gui_input doesnt work at all, but I expected that.
Using Input.is_action_pressed is identical to the _input method. It still catches the action no matter what else is going on. :/
I DID solve it, but in an ugly way that compels me to ask if there's something better. Basically, I added this script to the ViewportContainer:
func _gui_input(event):
if event is InputEventMouseButton:
$Viewport/GroundTiles.onMouse(event)
func _unhandled_input(event):
if event is InputEventKey && event.is_pressed():
$Viewport/GroundTiles.onKey(event)
And it worked. Hillariously, I had to use unhandled_input for keys and gui_input for mouse, and no other combination works.
I'm clearly not grokking this. Or is it that Viewports live in their own universe of events and require special plumbing like this to get away with such a design?