How do I lock a node or set its children as unselectable using GDScript?

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

Hello, I want to either lock a node or set its children as unselectable using GDScript.

I am aware that I can accomplish this by using the buttons in the toolbar.

However, I am creating nodes using new(), and I want to be able to lock those nodes created with script or set their children as unselectable.

I also know that I can click the buttons in the toolbar after the scene tree has been populated with the created nodes, but I don’t want to do that.

I want to simply change all the settings using GDScript alone.
Is it possible?

Thank you.

Hello HughMungus (good name btw).
What nodes do you want to make (un)selectable ? The answer will vary greatly depending on the nature of said nodes.

TheFamousRat | 2019-02-03 16:20

Thanks for your reply, Rat.

I’m creating a GUI system comprised of a bunch of custom buttons.
The custom buttons are built like this:

TextureButton (button)

NinePatchRect (button border)

NinePatchRect (button background)
Label (button text)

I want to be able to set the children of the top node (TextureButton) to unselectable.

Furthermore, once I have the GUI system laid out and looking how I want it, I want to lock those nodes (TextureButtons), so I can’t accidentally move them.

HughMungus | 2019-02-03 16:35

1 Like