How to prevent change to new scene and read previous click button from old scene

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

Hi, I’m just trying to change to a new scene in a simple way with a signal, and I’m having an weird? issue:

Main scene:
Node2d > Button (with signal):

func _on_Button_pressed():
  get_tree().change_scene("res://secondary.tscn")

Secondary scene:
Node2d:

func _ready():
   print('ready board');

func _process(delta):
   _read_input()

func _read_input():
   if (Input.is_action_just_released("left_click")):
		print('-----------------------');

When I click mouse left button in Main scene, everything works fine, and Secondary scene is presented on screen, but left_click released is read, so the code inside the if is executed. I would like to avoid this from happening.

Could anybody help me please? I don’t know what I’m doing wrong.

Code to blame: scenes_test.zip - Google Drive

:bust_in_silhouette: Reply From: Inces

Scene is changed while You hold mouse button and You release it after new scene is loaded. This is what You chose as Input - button released. It is best to design Input map otherwise, can’t You use just_pressed() instead of released? Why is this an issue, what do You want to happen on button release in your secondary scene ?

just_pressed()

did the work. Thanks.

I think that at the beginning I used that method, but I did some alterations to the original code, because I tried to use left & right click at the same time, and also release both at the same time, and I completely forgot about that method.

boquetipo | 2021-11-16 19:27