Signal or callback for any UI descendant changing

Godot Version

4.2.1

Question

I’m working on an adjustable UI element that I’m also using with @tool, which works great so far, with one exception. I’m having trouble being able to know when to refresh it. The key piece of information is that I have a top-level element with my script, and a whole bunch of children and grandchildren.

_draw() doesn’t seem to happen when I expect.

_process() works, but I assume that’s heavier than I need it to be. I suppose I could just run this one for the editor.

Any other combination of signals (especially minimum_size_changed, which is what I thought would work) doesn’t work when I reduce the size of an element.

So, I’ve got a label nested down in my UI. When that changes, bigger or smaller, I want to trigger a refresh on the whole tree. I tried setting up signal handlers on all the elements, but then I have to do that when they enter and exit and it felt like a lot of work to maintain.

So my winning solution at the moment is to use _process() with a frame cap (i.e. only run the refresh every x frames), but this feels less than ideal.

So the real question is: if I want to know anytime a descendant node has its minimum size changed, is there an elegant way to do that, short of putting a bunch of signal handlers on each one?

Setters and getters should help you with this.

Setters and getters AFAIK don’t apply when doing something like “making a change to one of several parameters to any of my children or grandchildren”

No.

Use Containers Using Containers — Godot Engine (stable) documentation in English They do the job for you (connecting the the needed signals of its children and sorting them) They will only react to changes in their children nodes not their grandchildren. If you break the chain like using a Node2D or using a Control that’s not a Container like: Container -> Panel -> Label they won’t update when changes happen like in the example: if the Label changes size, because Panel is not a Container, Panel won’t update the size so the Container won’t be notified and won’t update itself either.

You can create your own custom Container by extending Container and listening for its Container.sort_children or waiting for its NOTIFICATION_SORT_CHILDREN in its Object._notification() callback.

1 Like