Sorry if this has already been posted.

I am working on creating a 2D RPG at the moment and I have been racking my brain with this problem. When GUI elements are hidden, they still remain "hovered over" when they are next shown.

Essentially, there are certain elements in the GUI that become hidden when they are clicked on. For example the "next" button of the dialog box. I have a function which takes the mouse_entered() and mouse_exited() signals and changes the colour of the text. When the text is hidden it will remain in the mouse_entered() state and when it is shown again the colour will be in the hovered state and not the neutral state.

Am I missing something here? Am I being an idiot I cannot tell I have been trying to figure this out for a few weeks now and the only solution I've come to is that if I call .clear() on the labels and then add the text back in it seems to work. However, this is a really messy solution and it won't work for a lot of the elements that are children of things that do need to be hidden like colour rectangles.

Is there a more elegant solution that I am not seeing or do I need to reset the text every time and restructure my scenes?

Any help is appreciated!

Since they are signals I think you should be able to emit or disconnect/connect the signals. Haven't tried tho. Perhaps I'm wrong and the default ones can't be disconnected.

So I have tried what I think you mean by disconnecting them on hide() however, the colour is still incorrect on show(). Is there a way to have the hover update differently? Perhaps force an update every time that the visibility is changed? I know there is a default signal for visibility change but how do I force an update?

Have you tried emitting the mouse exited signal before you hide the node? The idea of disconnecting the signals would be so you wouldn't be able to emit them while the node is hidden.

Yes, I have tried to organise my code so that it is hidden and shown at the very last steps however this does not seem to have worked.

I have found a different solution though. I now have a script that is placed onto each label and it will receive a signal on the visibility change and on this it will find the mouse position and see if it intersects with the rect of the label. It is not a very elegant solution but it seems to work.

func _on_visibility_changed():
	var label = self.get_global_rect()
	var mouse = get_viewport().get_mouse_position()
	var label_size_x = label.size.x + label.position.x
	var label_size_y = label.size.y + label.position.y
	if mouse.x > label.position.x and mouse.x < label_size_x:
		if mouse.y > label.position.y and mouse.y < label_size_y:
			self.add_color_override("default_color", Color(0.5,1,0.5,1))
		else:
			self.add_color_override("default_color", Color(1.0,1,1.0,1))
	else:
		self.add_color_override("default_color", Color(1.0,1,1.0,1))

The above function is called every time the visibility is changed. The issue with this is it will include the whole rectangle shape rather than just the text because the visibility changed is on the control node and so does not interact with the label.

I had a similar problem, I have a buff icon that disappears with a timer. If you hover it shows the description of the buff. But if you don't move the mouse, when the buff disappears, the description is still visible, which doesn't make sense. I had to make a not pretty fix, but functional, just like you.

It just seems that hide and mouse_exited don't work well together sometimes.

Yeah exactly I'm not sure why either. Maybe it's a bug? Or could be just the way Godot works.

a year later