Mouse_entered signals repeatedly firing on hover, mouse_exited signals not firing at all

Godot Version

4.3

Question

Screen recording showing the issue

Repo with the project.

I have a scene for creating visual vectors, and I want to be able to detect when I user has hovered over the vector. I have created an Area2D with a CollisionPolygon2D that matches the .polygon property of the vector head exactly. I have connected the signals, and when I play the scene by itself, everything works as expected (the _on_area_2d_mouse_entered is called once when the vector head is hovered, and _on_area_2d_mouse_exited is called once when the mouse leaves it).

When I instance these vectors in code, however, the observed behaviour changes: hovering the vector head sees _on_area_2d_mouse_entered called repeatedly, and leaving the vector head sees _on_area_2d_mouse_exited called almost never (it it occasionally called, but I can’t find a pattern to when this happens).

If I instance the scene via the editor by dragging it into the tree, everything works as expected.

SOLVED

I was doing a queue_free in the physics process that was destroying each node - I was also re-adding the vectors to the scene using a function also called from the physics process.

The result is that every frame the vectors are destroyed, recreated, and the engine correctly believes that the mouse has entered a new vector (since the old one was destroyed in the previous frame).