So, after a bit of trial and error, I decided to write an Input Manager, to enable and disable the input depending on where I am on the interface, but can also be used inside the game itself.
For example, the initial input source will only be the actual game instance.
If i then open the menu, the input source will now be the menu, and the game input will be disabled. Each input source can have a sub input source to enable the handling of 2 input sources together, which suited my case, because i still want to be able to navigate the menu, while also handling some section specific input.
If i then toggle some action in the menu sections, the new input source will be the new popup or whatever needs to allow some user interaction, without also triggering any of the menu or section input. So the only input source is always the window in focus.
To do this i wrote the following global script:
extends Node
var active_input_source = null
var previous_active_input_sources : Array = []
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func change_input_source(new_source : Node):
if active_input_source != null:
disable_active_input_source()
var source = {
"main_source": new_source,
"sub_source": null
}
previous_active_input_sources.push_back(source)
active_input_source = source
enable_input_source(active_input_source.main_source)
func return_to_previous_input_source():
disable_active_input_source()
previous_active_input_sources.pop_back()
active_input_source = previous_active_input_sources[previous_active_input_sources.size() - 1]
enable_active_input_source()
func disable_active_input_source():
disable_input_source(active_input_source.main_source)
if active_input_source.sub_source != null:
disable_input_source(active_input_source.sub_source)
func enable_active_input_source():
enable_input_source(active_input_source.main_source)
if active_input_source.sub_source != null:
enable_input_source(active_input_source.sub_source)
func change_sub_input_source(new_source : Node):
if active_input_source != null:
if active_input_source.sub_source != null:
disable_input_source(active_input_source.sub_source)
active_input_source.sub_source = new_source
enable_input_source(active_input_source.sub_source)
func enable_input_source(source : Node):
source.set_process_input(true)
source.set_process_unhandled_input(true)
func disable_input_source(source : Node):
source.set_process_unhandled_input(false)
source.set_process_input(false)
To make it work you just need to call the changeinputsource method once on your main game instance script, or whatever instance controls your main input to switch between game and menu, and pass "self" as a parameter.
To return the input source to a previous one, I added a method to just do that. Just call the returntopreviousinputsource() from whenever and the current input source will be disabled, as well as any sub input source input, re-enabling the previous input source.
Hopefully this solution can help others with the same issue as me, and maybe you can come up with even better and versatile solutions