Please help me with a function that closes a Ui when clicking outside of it!

Godot Version

`4.2.2

Question

`Hey people! So I’m having a hard time coming up with a function that can do what I want.

For context I have these objects in my game that have some information and a button to upgrade the lvl of them by spending money. So I made a Ui that contais all the information and the button and already came up with a function that opens the Ui when I click the object.
Now what I want to do is basically close the Ui (object window) when clicking anywhere on the screen outside of it.
The Ui is a CanvasLayer that has a Sprite2D as a child node.

Any ideias on how I may do it?

Thanks for the help!

An idea I had (which may be bad) would be to extend an invisible polygon out to the edges of the screen/window while the UI is open. Then just set that polygon to when clicked, close the UI.

1 Like

Humm, good ideia! Don’t know if it is the most practical but might work haha. I’ll try it thank you!