How to get UIs elments' position in a space ?

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

I am making a game with Godot 4.0.stable where you can move characters around a 2D Top Down planet by clicking on the position you wish the character to move to, just like in Rimworld.

I would like to implement UI elements such as a button to switch scene, a fast foward, a pause etc…

However my issue is that when I click on UI elements it moves the player to the coordinate under the UI element.

For example here : Screenshot by Lightshot The red character is chosen, when I click on the top left button the function associate to the button is used but the player will still moves under the button. I would like to know if there is a way to do somehting like :

If Input.is_action_just_pressed("left_click") and click_position != UI_elements_space:
    #move the character
    #dont move the character

I tried to get every UI elements position and multiply by them by their size so I can add it so the condition. But I have to implement every new element of the UI this condition, which is pretty tedious and not clean.

I know there is a better and much easier way to do it. I just don’t know how…

Any help is appreciated!

:bust_in_silhouette: Reply From: Nickyroo

Im having trouble understanding your main question, but regarding a much cleaner and easier way to Position and Hold UI elements with their Multiplications… I would recommend you to try out these cool advanced arrays called DIctionaries!

for Instance, Instead of lame Arrays which are Just “var MyArray =
A Dictionary can Store Multiples of Data… for instance…

var MyButtonDictionary = {}

MyButtonDictionary[1] = [Vector3(Whatever Position I want), Vector3(My Position Offset)]

And then if you Check whats in MyButtonDictionary[1], It Would be That position with your Desired Offset

Ultimately Allowing you to have all your information safely stored in 1 Neat Array like Variable

If I do come to an understanding of Your Main Question, i will attempt to answer that Portion

I like the idea and would have used it if I hadn’t found something better.

Neestrid | 2023-06-06 06:50

:bust_in_silhouette: Reply From: M.Kh

It is simply solved!
You can use the pause feature. To do this, put the function in your code and set the state of the node with the script to always so that it can run again after stopping, if your script is connected to the player you need to create a signal and pass the user commands to the higher node .
See Godot or GitHub documentation for this!

If you don’t like this way, you can keep it fixed by constantly sending a position to the player, which may cause a jittery state and slow down the processing.

I don’t really like it this way, and yes you’re right the second option might have caused jitter, but thx anyway :slight_smile:

Neestrid | 2023-06-06 06:52

:bust_in_silhouette: Reply From: Neestrid

I managed to fix it, it seems like there is an order for Godot to process the mouse click.

First: _input(event)
Then: Control.input_event(event)
Finally: _unhandled_input(event)

See more: Using InputEvent — Godot Engine (stable) documentation in English

So what I did was to use _unhandled_input(event) to move the player, so if I clicked on a UI element it would not trigger the func to move the player.

func _unhandled_input(event: InputEvent) -> void:
	if event is InputEventMouseButton :
		if event.button_mask == MOUSE_BUTTON_MASK_LEFT:
			#move the character