Can't get the sender of mouse_entered signal

Godot Version

4.2

Question

So i was trying to implement a click and drag system. I’m pretty new so i’m basically just learning as i code. I made a script where if the mouse enters an area2d, it gets the parent of the sender of the signal (which is a sprite) and moves that according to the mouse. Only problem is, i cant get the sender of the signal. Everything else works fine. (i manually connected the mouseentered and mouseexited signals to the main node, where the script is)

extends Node2D
var part
var mousein_area
var signal_sender
@onready var part_place_holder = $PartPlaceHolder
@onready var area_2d = $PartPlaceHolder/Area2D

var previous_mousepos = Vector2()
var current_mousepos = Vector2()
var mouse_delta = Vector2()

func _ready():
	previous_mousepos = get_viewport().get_mouse_position()
	mousein_area = false

func _process(_delta):
	
	if Input.is_action_pressed("LMB") and mousein_area and part != null:
		current_mousepos = get_viewport().get_mouse_position()
		mouse_delta = current_mousepos - previous_mousepos
		part.position += mouse_delta
		previous_mousepos = current_mousepos
	else:
		previous_mousepos = get_viewport().get_mouse_position()


func _on_area_2d_mouse_entered(sender):
	mousein_area = true
	signal_sender = sender
	part = signal_sender.get_parent()
	print(part.name)


func _on_area_2d_mouse_exited():
	mousein_area = false
	part = null

the error (happens when the mouse enters the area):
E 0:00:02:0175 emit_signalp: Error calling from signal ‘mouse_entered’ to callable: ‘Node2D(onescript_to_rulethem_all.gd)::_on_area_2d_mouse_entered’: Method expected 1 arguments, but called with 0.
<C++ Source> core/object/object.cpp:1140 @ emit_signalp()

The signal doesn’t take any arguments, this isn’t how this signal works, see mouse_entered

There isn’t any “sender” involved here, the signal doesn’t come from any other node

I see, is there a workaround? Maybe some other signal? I really don’t want to manually assign every Area2D. Thanks.

No because the concept you’re talking about doesn’t exist, there’s no “source” of this, what are you trying to do? What does "sender’ mean?

I want to be able to hover my mouse over any area2d, and when i do i want the script to get the parent of that area2d, and move it.

The parent of the area is just get_parent, just connect it to a signal on the area itself

1 Like