Change input control (or focus) from Player to Interface

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dynamite09

Hi,
I’ve created a Player that can talk with some random npcs. When the player is facing the npc, the player’s raycast detect the npc and if the player uses “ui_accept”, the dialogue start.
When the dialogue is over (to skip further the text, the player uses “ui_accept”), the dialogue starts again because when the player uses “ui_accept” he’s still facing the npc.

The player’s script:

func _physics_process(delta):
get_input(delta)
get_object_collided()

func get_object_collided():
	if canMove:
		var target = $RayCast2D.get_collider()
		if target != null:
			if target.is_in_group("NPC"):
				if Input.is_action_just_pressed("ui_accept"):
					emit_signal("startDialogue", target)

The Interface’s script:

func input(event):
	if global.isTalking:
		if Input.is_action_just_pressed("ui_accept") and (dialogueState != dialogueLenght):
			dialogueState += 1
			updateDialogue()

So, my question is: "how can I switch the inputs from the player to the Interface and viceversa?

:bust_in_silhouette: Reply From: exuin

You can try using the _unhandled_input() function for the player. It will only be called on events that haven’t been consumed by something else yet so just make sure that the GUI consumes the event. More info here.