Download

UMG button communication - how?

I have a User Widget that contains another User Widget. The child widget has some buttons that are populated dynamically. I want an event to trigger in the parent Widget when one of the child buttons is clicked, and to pass a variable to it.

Button Clicked in Child Widget > Event and Variable passed to Parent Widget.

Trouble is , I can’t for the life of me figure out how to do this in a way that’s not extremely messy. There doesn’t seem to be a way for the Child User Widget to know about the parent it resides in.

There’s a “get parent” function, but casting from that doesn’t expose user widget types, just the defaults.

I feel like I must be missing something really obvious…

The best way to do this is to have the button hold a reference to the parent that is set when it’s created.

MenuWidget houses ButtonWidget.
ButtonWidget has a variable reference to MenuWidget.
MenuWidget creates ButtonWidget set dynamically and sets the MenuWidget variable in each ButtonWidget to be “self.”
ButtonWidget then calls the function in the MenuWidget variable on click.

This used to cause REINST errors (cyclical dependency) but is no longer an issue.

Ah, thank you!