How to make folding menu?

there is an easier way to do this. also works with scroll containers. with godot 4 (havent tested in in godot 3).

use a control node and inside it put your container nodes with their inputs/button/labels etc.
eg.
-control
—-collapse button/checkbutton/btn_container
—-container/scroll container(top level)
--------inputs/other containers with inputs

Set the custom_minimum_size.y of your top level container for inputs, and the control node, to whatever size for the content. + btn.custom_minimum_size.y for the control node.

set the button or button container custom_minimum_size.y to however big it has to be to show the button.

add signal from your button to your control node script.

add script to your control node in the signal function. eg.

func _on_check_button_toggled(toggled_on):
------if not toggled_on:
------------control_node.custom_minimum_size.y = collapse_button/button_container.custom_minimum_size.y
------------top_inputs_container.scale.y = 0
------else:
------------top_inputs_container.scale.y = 1
------------control_node.custom_minimum_size.y = top_inputs_container.size.y

remmeber to enable clip_contents on scroll_containers so the children dont show up outside the container.

you can instance/add the control nodes in another scroll container/other container, if you want, and they will still collapse.

explanation:
the control node size gives the volume to the content so nothing overlaps if put inside another container.

while the top level inputs container size shows the content (you can use show(), hide() instead of scaling it, if you want).