UI on_mouse_exit does not work if any UI is behind it

Maybe. Depends on how you scaled it and which options you choose. Control nodes behave different if they are under a Container node.

For the simplicity, I would add a Panel first and your RightClickInventory scene under it to test if the disappearing works, then implement the item grid to the panel later.


This should be the proper layout and code

And how it works when I try it:

Is your Background node stretched on the full screen as well? Because if so, it will block this signal. You need to move this Control node after the Background node.
And remove this whole Area2D at the end too, it might be messing with the input as well

Please try to do these:
1- Remove Area2D and collisionshape2d. You should never need that under control node
2- Your code seems to be attached to node named Control node. So your mouse needs to get signal from that node. Why do you have that node? I don’t think you need it.
3- Remove the node named Control
4- Attach your code to your node named Background


Ok moved things and removed the Area2D

It works for the most part, but for some reason also works when the mouse enters the area?

Connect it to the mouse_entered, not mouse_exited, and see if this will be triggered twice too?

The Area2D was from a previous build and has been removed.

The code working on Control is how I am setting it up while trying wchc’s recommendations.

I tried switching the code to the Background, but nothing changed. It works the same as having it on Control. Also has the same problem where the exit signal also calls when the mouse enters the area

I think because the buttons are getting the signal so you are effectively leaving the area of the node:

1- Remove the node named Control
2- Attach your script to the node named Background
3- Make VBoxContainer (with its children) as a child of Background.


That is also triggering on enter and exit. Which is very odd

Unfortunately that makes it so if I hover over any of the buttons, it counts as leaving the background area. So that signal that I left the box would still be sent

What if you uncomment both mouse_entered and mouse_exited? Does it trigger double then?


It does unfortunately trigger both twice

For all the buttons, you should also select Mouse filter → Pass

Normally buttons default Mouse filter is Stop. Which means when your mouse is over a button, mouse event does not propogate up to the parent node. Because of that your main node (background) thinks the mouse is not on it anymore.

Make sure same is selected for the Vboxcontainer. It’s mouse filter is Pass by default, so it should be ok. But just check just in case.

Still has the same problem. It will trigger when entering and when leaving the area

Oh yeah, they have all been set to Pass on all of them and my tests

This is my scene and it works as you wanted.

And the code:

extends TextureRect

func _on_mouse_entered() -> void:
	print('mouse entered')

func _on_mouse_exited() -> void:
	print('mouse exited')

EDIT:

I connected the signals from the editor. I never use the notation in your code.

I use this if I want to use the script for connecting signals

	mouse_entered.connect(_on_mouse_entered)
	mouse_exited.connect(_on_mouse_exited)

I know what’s up now. You should expand your root note “Right_Click_Inventory” to stretch to the Full Rect as well.
It might not look correctly, but you’d need to adjust the look later once you get this working.

@lastbender is suggesting a similar approach, but just made it all in a tree structure, whereas mine was more flat.
It’s a mess when 2 people reply at the same time, so I’ll just let @lastbender guide you further.

In case of any issues, let me know.

So this is 99% working!

Only problem now is the Background doesn’t show the texture that I picked? The bounds are still there and working,as far as I can tell the code is working completely correctly.

Haha yeah its been interesting to get two people trying to help. but it looks like lastbender’s suggestion of the way to build the scene has worked! well, almost entirely, I can’t see the image. But the code is working fine.

The only real trouble is that I don’t really understand why that code is working, and the stuff we have been trying doesn’t. I mean I’ll take the win, but would still love to know what is going on with it.


This is what it looks like with your setup

But this is what happens when it comes into the inventory scene