Can't Load a New Scene

Godot 4.4

I am trying to change a scene, with a fade-to-black transition, when an Area2D is clicked on. However, the mouse will automatically click twice, leading to the scene not loading. This problem is solved when I take out the “await” line. I have been able to use the “await” line previously in a similar context.

Here is the code I am trying to use. This is in a general main script:

extends Node2D

func _on_area_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
		print("Inspecting the hole in the wall")
		TransitionScene.transition()
		await TransitionScene.on_transition_finished
		get_tree().change_scene_to_file("res://scenes/hole.tscn")

Here is the code in a similar context that works. This code is attached to the object being clicked:

extends Area2D

func _input_event(viewport, event, shape_idx):
	if event.is_action_pressed("click"):
		print("Inspecting The Tower")
		TransitionScene.transition()
		await TransitionScene.on_transition_finished
		get_tree().change_scene_to_file("res://scenes/tower_inspection.tscn")

Here is the code for the transition scene:

extends CanvasLayer

signal on_transition_finished

@onready var color_rect: ColorRect = $ColorRect
@onready var animation_player: AnimationPlayer = $AnimationPlayer

func _ready():
	color_rect.visible = false
	animation_player.animation_finished.connect(_on_animation_finished)

func _on_animation_finished(anim_name):
	if anim_name == "fade_to_black":
		on_transition_finished.emit()
		animation_player.play("fade_to_normal")
	elif anim_name == "fade_to_normal":
		color_rect.visible = false

func transition():
	color_rect.visible = true
	animation_player.play("fade_to_black")

Implement the thing without using await.

await always waits for signal, so everything you can implement with await you can equally well implement with regular signal callback, only less bug prone.

awaits are psychoactive and then to bend one’s perception of space and time.

I’ll take a look at that, thank you!

It looks like I get the same double-clicking issue in other contexts using this part of the script, whether or not an await function is also used:

func _on_area_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:

Well it catches both; press and release events. You need to check event.is_pressed() to determine if the event is press or release.

This solved my issue! Thank you!

func _on_hole_area_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
	if event.is_pressed():
		if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
			print("Inspecting the hole in the wall")
			TransitionScene.transition()
			await TransitionScene.on_transition_finished
			get_tree().change_scene_to_file("res://scenes/hole.tscn")