Node Spawning in Bizarre Position, Despite Container Layout Mode

Godot Version

4.2.1

Question

I have a menu built with a cursor that is supposed to spawn next to the first menu item when the menu is opened. The menu has a function on_open() that runs when the menu is opened, and in that function there is a trigger for the cursor to run its set_cursor_from_index() function which places the cursor in the right position. The issue I am having is that the cursor first spawns in a position way off-screen (both x and y being negative numbers) and only shows up next to the menu options when it reads input, at which point it snaps into the correct place. Here’s the set_cursor_from_index() function:

func set_cursor_from_index(index : int) -> void:
	menu_item = get_menu_item_at_index(index)
	print(menu_item)
	
	if menu_item == null:
		return
	if  menu_item != current_menu_item:
		focus_changed.emit()
	
	current_menu_item = menu_item
	
	var menu_item_position = menu_item.global_position
	
	print(menu_item_position)
	
	var cursor_x = menu_item_position.x - size.x - cursor_spacing
	var cursor_y = menu_item_position.y
	
	global_position = Vector2i(cursor_x, cursor_y) + cursor_offset
	
	next_menu_item = get_next_item_at_index(index + 1)
	if next_menu_item is Slider:
		next_menu_item.set_focus_mode(Control.FOCUS_ALL)
		next_menu_item.grab_focus()
	else:
		menu_item.set_focus_mode(Control.FOCUS_ALL)
		menu_item.grab_focus()
	
	cursor_index = index

When I print(menu_item) towards the beginning of the function, that behaves as expected. However when I print(menu_item_position), I see the unexpected position that results in the cursor being off-screen. What’s interesting to me is I can see the menu option in the correct place, just not the cursor. I’ve also attached the scene’s path to the node in question in case that helps. Any ideas?

EDIT: it is also interesting to note that the position the class_ui_slot is spawning in initially contains half pixels, not really sure what to make of that. But the position is (-340.5, -278.5).