UMG Widget 'Event Drilling'

Hey, I am coming from a React background and there we have a situation called “prop drilling”, which describes the process of taking some data and passing it through every component in the tree manually.

I am encountering a similar situation using UMG widgets, where I have a custom button, being several layers of custom UMG components deep, that is dispatching a custom OnClick event. Now I had to create an event dispatcher on every level of the hierarchy so that I could pass that event onto the root component, where the side effects are located at.

Is there a more elegant way to handle custom event dispatchers without introducing side effects in the corresponding widget?

1 Like

You should use the new View-Model for binding data, events to UMG widgets: UMG Viewmodel | Unreal Engine 5.1 Documentation

2 Likes

You could drill a widget tree in the following way:

  1. Create BlueprintInterface to send events to desired widgets:

  2. Add the interface to your widgets:
    image

  3. Create a macro library with the following macro:

  4. Use the macro to send events from the bottom widget to every upper widget in the tree that does implement the interface:

  5. Catch event:

Example:
Widget Tree:
image
image


image

Runtime:
Drill

My Products

2 Likes

That looks actually great. Too bad that our project currently is blueprint only and I don’t want to introduce C++ just for viewmodels

1 Like

Thanks, that looks great! I will implement something similar to that

I’m excited about using view models when they finally come to BPs.

1 Like

Strong agree, I primarily work in C++ but ViewModels and UI stuff are much easier to work with as BP.