Setting panel node .size and .position does not clear it from screen

Godot Version

4.2

Question

I had this working before refactoring it to it’s own function when it was just in process() but when I attempt to use clear_area from this parent node:

func _process(_delta):
	handle_panel(UnitSelectionPanel, "unit_selection_panel_updated", "rts_drag_select")
	handle_panel(UnitPlacementPanel, "unit_placement_panel_updated", "rts_drag_position")


func handle_panel(panel: Control, signal_name: String, action_pressed: String) -> bool:
	if Input.is_action_just_pressed(action_pressed):
		panel_start_position = get_global_mouse_position()
		is_dragging = true
	if Input.is_action_just_released(action_pressed):
		is_dragging = false
		emit_signal(signal_name, panel_start_position, panel_end_position, panel_area)
		panel.clear_area()
		print("emitting signal")
		return true
	if is_dragging:
		panel_end_position = get_global_mouse_position()
		panel.draw_area(panel_start_position, panel_end_position)
		var new_area = panel.get_area()
		if new_area != panel_area and new_area.size.x > 0 and new_area.size.y > 0:
			panel_area = new_area
	return false

We get to the clear_area function directly on the panel node:


func clear_area():
	self.size = Vector2(0, 0)
	self.position= Vector2(0, 0)
	print("clearing")

However it is still visible on the screen. I know this doesn’t technically clear it but the panel should not be seen since it is a 0 size and at the origin. I had this working when the parent node was running a child_node_name.size = 00 and position so when calling in process from the parent node but I would prefer this specific function to be in the child’s script. Don’t know where I am going wrong.

I also just now noticed the event seems to be firing when I just left mouse click despite my input map setting rts_drag_select to only work when shift + left mouse click is used.

Use visible = false to hide the CanvasItem (which is inherited by Node2D and Control). Modifying the size property sometimes doesn’t affect Control nodes.

I had attempted that as well to no fix. Besides I believe the visible attribute is an engine only representation at runtimd ths attribute doesnt care about that boolean. I could free the panel from the tree but doesnt that prevent it from being used in the same way?

The visible property is indeed for developers, but if you prefer to remove nodes from the tree, you can code as follows:

# Removes the node tree from the scene tree, but don't free them.
remove_child(panel)

...

# Add the node tree back when needed.
add_child(panel)

This technique is not some fancy bugs, instead, this is recommended in the documentations.

Right agaib though i would need to add it back to the tree every time i want to use it again? That does not seem very efficient as this is a ui drag and drop selection panel it could potentially be called every second

Kinda like starting a car over and over again its better on gas to just start it once and leave running. Obviously this may not translate but that’s part of fhe question here.

I have troubleshot some more. I don’t have a full resolution but the issue seems tied to my use of the handle_panel twice in the _process function. If I drop it two only one chance of handle_panel being called I don’t get any failures and the self.size/self.position setting to 0,0 works fine.

The visible property does work for me. There are show() and hide() methods, both just setting the visible property. They all worked fine in my project.