InputEventMouseButton called twice and the node "RichTextLabel" is null on the second call

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

I have created “Node2d” object and “RichTextLabel” as its child. The script contains the following code to print the “$RichTextLabel” on mouse click. For every single mouse press (not release only pressed) this method is called twice and and first time the “not null” and then in the second call its prints “null”. There are 2 bugs. I expect to call once on mouse press and it should not be null. What is wrong in the following code ?

func _input(event):
 	if event is InputEventMouseButton:
  		if $RichTextLabel:
			print("not null")
:bust_in_silhouette: Reply From: deaton64

you’re not checking if the button is pressed, just if the event is a mouse button.

if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.is_pressed():
:bust_in_silhouette: Reply From: bob333

Found the issue. I had set the script as Main scene and also added it to the autoload. That’s why it was receiving the mouse events twice. But i guess one of the instance was printing the $RichTextLabel node as null, due to internal implementation.