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()