Digging through widget hierarchy like this is generally as awkward as you think and requires as poor an implementation as Chat GPT suggests - it’s known for that.
A much better question here is why you’re trying to do it - as in, what is the actual scenario? What are we doing? In case you do not want to spill the beans, one could generally approach things like so:
- widget A
- widget B
- widget C
- widget B
A can talk to to B and C directly (a dispatch may be more convenient if we create children on the go)
B can talk to C directly.
B can talk to A via an Event Dispatcher.
C can can talk to B via an Event Dispatcher.
C can talk to A via an Event Dispatcher that A should bind - is this your scenario?
Whether it’s static or created dynamically does not matter much really. But again, how to connect the pieces depends on what we’re doing, exactly. There are instances where you must pull data out of an object and loop look-ups are necessary evil. Avoid it if you can, Event Dispatchers work could really well here.