Area2D mouse_entered randomly not working?

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

I have a GDScript that displays a tooltip when hovering the mouse over an item. The Item scene extends Area2D and connects the mouse_entered / mouse_exited signals to show / hide the tooltip. Here’s what’s happening:

I’ve noticed that it consistently happens (to some of the items) when standing on certain positions, but can’t figure out why. I have a Player scene with a Camera2D child (the current camera) with default settings.

The item sprites have an outline shader, but the issue still happens without it.

Here’s the signal’s code:

func _on_Item_mouse_entered():
	ui.offset = get_global_mouse_position()
	ui_container.visible = true
	tween.interpolate_method(self, "set_shader_border", 0, 2, 0.1)
	tween.start()


func _on_Item_mouse_exited():
	ui_container.visible = false
	tween.interpolate_method(self, "set_shader_border", 2, 0, 0.1)
	tween.start()

Any ideas?

make sure input_pickable is enabled on those Area2Ds

timothybrentwood | 2021-05-12 06:36

yes, it is :confused:

oblibon | 2021-05-12 12:34

Oh wow I just looked at the video. Can you post your node structure? What node is this script attached to? And just out of curiosity what is ui.offset used for?

timothybrentwood | 2021-05-12 13:33

Sure. The script is attached to the Item node (see image).

https://i.imgur.com/96fxaAy.png

ui.offset is used to reposition the tooltip (onready var ui = $HoverUI), since I have it on a CanvasLayer (I may have to rework this and read a bit more about CanvasLayers, the idea was to prevent the tooltip from being affected by the world’s lights and visual effects. The issue still happens without changing the offset though.)

Here’s the whole Item.gd in case it’s useful: ###### en# Item class that represents an item on the ground or inside a ches - Pastebin.com

oblibon | 2021-05-12 15:12

That is definitely some strange behavior. I don’t really see you doing anything out of the ordinary in the code. Have you tried adding print() statements to the methods to see if they fire? This would isolate it to either a signal notification thing or a graphical thing.

timothybrentwood | 2021-05-12 17:04

OH! I have had behavior like this before. It was with two control nodes being drawn on top of each other though. The one underneath would eat the input and it wouldn’t be propagated to the one on top. Could something similar to that be happening here? Try setting the mouse_filter property of your control nodes to Ignore

timothybrentwood | 2021-05-12 17:12

That was it! I had a RichTextLabel on top of the player’s head for displaying chat messages. That’s what was eating the mouse_entered signal. Changing the mouse_filter property to Ignore fixed the issue. Thanks a lot!

oblibon | 2021-05-12 20:11

No problem! That one got me for a few hours when it happened to me hahaha! Glad I could save you the time.

timothybrentwood | 2021-05-12 20:26

:bust_in_silhouette: Reply From: timothybrentwood

There was a RichTextLabel on top of the player’s head that was consuming the mouse_entered signal from the Area2D. Changing the mouse_filter property to Ignore resolved the issue.