Self.connect isn't working

Godot Version

Godot_v4.2.1-stable

Question

When using this code over here:
image
Its not working and these are the nodes:
image
when holding mouse over the area2d it doesnt print “HI” any possible fixes

I think it will be like this:

self.mouse_entered.connect(_on_area_2d_mouse_entered)

The script is connected to the Sprite not the area 2d so it shows this error:
image

ok, so to like this:

$Area2D.mouse_entered.connect(_on_area_2d_mouse_entered)
1 Like

It worked but does it work if i have multiple diffrent area 2d’s ??

Yes, of course it will work

1 Like

Thanks for your fast replies !!! I thought it would take 1-2 days to reply But this is fast amazing !

1 Like

Wait i’ve tried it but when i connect it just connects the nodes with the same name (Area2D) can i change this ?

Use export variables, or scene unique names, and then use the code:
For scene unique name

%Area2D.mouse_entered.connect(on_area_2d_mouse_entered)

Remember to register the Area2D as a scene unique name. This isn’t the best way, especially if the node’s location changes,or there are more than 2 Area2D, as that would require different names. Which is why I recommend the
Export Method

extends Node
@export var area2d:Area2D
func _ready():
area2d.mouse_entered.connect(on_area_2d_mouse_entered)
#add the tab, my mobile isn't allowing me to.

This keeps the node and automatically updates the node path, though you would need a different var for every area2d. Not like you wouldn’t need to change variable names in the other method too.

I cant get it to work

I can’t understand what do you want to say but for connecting multi nodes you can do this:

$Area2D.mouse_entered.connect(_on_area_2d_mouse_entered)
$Area2D2.mouse_entered.connect(_on_area_2d_mouse_entered)

Also I understood something another of your question, if you want to change the name of this function _on_area_2d_mouse_entered for your each node, you can do this like

func _on_area_2d_mouse_entered():
   pass
func _on_area_2d_2_mouse_entered():
   pass
1 Like

oh so i can just connect them all to 1 node that’s excatly what i wanted thank you !!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.