Ignore input from get_axis when UI is selected

Godot Version

4.2.2.stable.arch_linux

Question

I have a basic camera controller which moves the camera around with WASD with

Input.get_axis("move_camera_left", "move_camera_right")

This works fine, except that the camera is moved around when typing in the UI (like in a lineedit). For other things like scrolling, I can use _unhandled_input, but this doesn’t work for camera movement since I need access to delta time. Does godot have a way so get_axis will return 0 if a node is selected or something similar? Or do I have to write some solution myself?

Take a look at how others do it, e.g. GitHub - ColormaticStudios/quality-godot-first-person-2: An actually good first person controller for the Godot Engine (version 2)

When you press ESC in their demo the fps control is disabled.

Unfortunately, that’s not really the behavior I’m looking for. My UI is and should be active at the same time as the camera can move.

My problem is that I don’t want the camera and the UI to be explicitly aware of eachother, but have my camera not react to input that should only be used as input in something like a LineEdit

a solution might be to have a static or an autoload class that contains a flag that you test for, e.g.

var is_ui_focused: bool = false

You could set this to true/false when having your ui focused, and check if its active before polling input