Popup node position in Window node

i am making right click menu for inventory items, while thats going good, i can’t get to popup node to clicked position.

video :
https://streamable.com/cn23wk

node hirerarchy

@onready var right_click_menu: Popup = $"../right_click_menu"

var pos : Vector2


func _input(event: InputEvent) -> void:
	if Input.is_action_pressed("right_click"):
		pos = event.position
		right_click_menu.popup(Rect2(pos.x,pos.y,right_click_menu.size.x,right_click_menu.size.y))

i did try to add a control node and make it root and make it full rect, that works, but when i click on the inventory(window node) focus goes on to inventory and cant get to popup open, its only work on it control that way.

how can i solve this, or is there better way to make right click menu.

i did aslo try make it instance to clicked position, but instanced scene allways goes clipped by window node and can’t see the instanced right click menu completely.

bdw this inventory scene when its called, its added to a canvaslayer as it child.

edit:
with control node video:

https://streamable.com/vl0j1e

hirerarchy

The issue is that the Window event position is relative to its top-left corner and the Popup.popup() expect the position to be relative to the top-left corner of the main Viewport.

You can fix that by changing pos = event.position to pos = get_viewport().position + Vector2i(event.position)

Also, don’t mix any of the _input()/_*_input() functions with the Input singleton as it’s redundant. The event parameter has all the information you need already:

@onready var right_click_menu: Popup = $"../right_click_menu"

var pos : Vector2


func _input(event: InputEvent) -> void:
	if event.is_action_pressed("right_click"):
		pos = get_viewport().position + Vector2i(event.position)
		right_click_menu.popup(Rect2(pos.x,pos.y,right_click_menu.size.x,right_click_menu.size.y))
1 Like

thank you, that solve it problem for me :slight_smile:

https://streamable.com/tcq4e6

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.