+2 votes

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?

in Engine by (30 points)

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?

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.

1 Answer

+1 vote
Best answer

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.

by (84 points)
selected by

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

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.

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.