0 votes


Enjoying godot 3 but I have a small problem.

I use the mouse with pressed button to control the camera in a 3D scene.

func _input(event):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_LEFT:
            if (Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED):
                pantilt = false
                pantilt = true

But I also have an onscreen GUI composed of Buttons with associated functions like:

func _on_ButtonMap_pressed():
       worldmap.visible = not worldmap.visible

It works except that pressing the 2D button does the _on_ButtonMap_pressed func as expected but ALSO triggers the _input event on the 3D scene script, which captures the mouse and then frees it. This causes the mouse to reset to the centre of the screen each time the button is pressed.

In the Button inspector, mouse->filter is set to stop. The camera script is a per scene instance and the GUI script is a global autoload, which I think might mean the camera script always receives the events before the Button does?

Any ideas on how to stop this behaviour?

in Engine by (206 points)

yeah, I think the behaviour is because the buttons are in a singleton that is autoloaded.

setinputas_handled() doesn't consume the event before it gets to the 3D camera _input so I think that means the local camera node is processed before the singleton?


1 Answer

+1 vote

The solution was to place my mouse event code under:

func _unhandled_input(event):

instead of:

func _input(event):

_input is processed before controls and unhandledinput is done afterwards which is the behaviour I needed.

by (206 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.