Change Node Size (tool, 2D)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bojjenclon
:warning: Old Version Published before Godot 3 was released.

Is there a way to change the size of a node manually through GDScript? I’m writing an editor tool that draws textures in an area defined by exported variables, and I’d like for the entire textured area to be selectable in-editor. In other words, right now even though the node technically draws a very large area, you can only click it in a very small area near the top-left of the node. Is there a function to change the node’s size so I can have a large click-area for it in-editor?

There is a get_item_rect() method inherited from CanvasItems that seems to correspond to what you are looking for, but I see no setter. edit_set_rect(), maybe?

Zylann | 2016-03-20 02:55

Yeah I tried that before posting this and, unless I misunderstood how to use it, it simply changed the scale of the node. That’s not really the behavior I was looking for, since this in turn affects things like the _draw() method.

bojjenclon | 2016-03-20 06:23

:bust_in_silhouette: Reply From: Kermer

Use Control and its _input_event function, which only triggers when the input happens inside Control’s rect.
Then just set up it’s size (set_size(Vector2)) and you’re done.

As I remember _input_event is connected to the script by default, like _process, _input, etc.

Perfect, Control (and its accompanying functions) was exactly what I was looking for. Thank you! :slight_smile:

bojjenclon | 2016-03-20 17:46

Could you explain what you mean by “use Control” more?
I tried using Control.set_size(size) inside of an object whose editor box i wanted to re-size, but get the error:
Invalid call. Nonexistent function 'set_size' in base 'GDNativeClass'.

Edit: Adding a child Control node and using get_node("Control").set_size(size) does nothing and gives no error, I’m really lost by what “use Control” means exactly.

nanimonull | 2016-09-01 20:00

By Control I mean Control object or any object inheriting it.

Lot of Control objects are not visible by default and in this case set_size() (together with position/rotation) is used just to define area for which the _input_event function will fire.

Kermer | 2016-09-01 20:18