The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

In my game, there's a viewport that has, as a child, a world.
The viewport takes half the screen space, and on the other half there are buttons that are not children of the viewport.
However, when clicking on those buttons, the input is consumed by nodes that are in the viewport world (and of course are not visible right now through the viewport - since the click was outside the viewport) instead of the buttons that are outside the viewport.

The viewport itself was not clicked on, but the world inside it consumed the input. Is that a bug?

Godot version 3.2.3
in Engine by (176 points)
edited by

3 Answers

0 votes

Every node consume input event, if you want the node to only consume input when mouse cursor is in its borders, then You have to specify such conditions. Buttons and some control nodes use on pressed signal, so You don't have to do this with them.

by (8,188 points)

Thanks. Isn't it part of the viewport's functionality, to filter out inputs that take place outside its borders (that is, outside the world that it presents) ? It makes sense to me that it should be.

I don't know about that.
However input is filtrated in some degree, check unhandled-input in documentation, this is propably what You are looking for

0 votes

It seems like setting viewport's handle_input_locally property might be the solution.

by (176 points)

Sorry, I was wrong, This property doesn't solve the issue.

+1 vote

I ended up adding this script to the enclosing ViewportContainer:

func _input(ev):
    if ev is InputEventMouseButton:
        $Viewport.gui_disable_input = false
        if ev.position.x<rect_position.x or ev.position.y<rect_position.y or ev.position.x>(rect_position.x+rect_size.x) or ev.position.y>(rect_position.y+rect_size.y):
            $Viewport.gui_disable_input = true
by (176 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.