# Override Child Widget Function/Event?

**URL:** <https://forums.unrealengine.com/t/override-child-widget-function-event/486359>\
**Category:** Community & Industry Discussion\
**Tags:** button, override, unreal-engine, question\
**Created:** [July 18, 2021, 1:09pm UTC](https://forums.unrealengine.com/t/override-child-widget-function-event/486359 "2021-07-18T13:09:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_3ad9ae12](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3ad9ae12](https://forums.unrealengine.com/u/anonymous_user_3ad9ae12)\
**Post date:** [July 18, 2021, 1:09pm UTC](https://forums.unrealengine.com/t/override-child-widget-function-event/486359/1 "2021-07-18T13:09:37Z")

</div>

Hi Unreal Community!  
For a piece of UI I’m making (I’ll call it “Widget1”), I want it to have 3 child widgets, all of which inherit from a “HUD\_Button” class that has some built-in functionality I want. However, I also want each child to create a different menu when it is clicked. Is it possible to override the OnClicked, OnPressed, etc. functions of the button widget from each child widget, in Widget1? If not, is it possible to override a custom event? (which I could set up to run on the button event)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 18, 2021, 7:21pm UTC](https://forums.unrealengine.com/t/override-child-widget-function-event/486359/2 "2021-07-18T19:21:29Z")

</div>

Quite possible, indeed.

## Parent widget:

 ![344427-screenshot-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/f/1/6f1a012531a7f8146e771c076f908226623bac16.png)

## Child:

 ![344428-screenshot-3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/d/3/ed3764224c1ea32f4c40362915be4dcb0519df0a.png)

- top bit: child overriding parent’s onClicked.
- bottom bit: override and optionally call parent’s event (works for functions, too, ofc); or just call parent’s event / function (very bottom)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3ad9ae12](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3ad9ae12](https://forums.unrealengine.com/u/anonymous_user_3ad9ae12)\
**Post date:** [July 18, 2021, 8:51pm UTC](https://forums.unrealengine.com/t/override-child-widget-function-event/486359/3 "2021-07-18T20:51:27Z")

</div>

Ah, I understand what you mean, but I meant an instance of a source widget, as in a “Child” in the widget hierarchy of the Designer. I have a widget with 3 “child” widgets in the hierarchy, all marked as “is variable”.

Is there a way to override (in “Widget1”) a function that is defined on the source widget of the “child” in the hierarchy? e.g. I have a function called “ButtonPressed”, called when the button within the source widget is pressed, the behavior of which I want to customize for each instance of the source widget within “Widget1”. Thank you so much for your answer; I should have been clearer!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 19, 2021, 8:08am UTC](https://forums.unrealengine.com/t/override-child-widget-function-event/486359/4 "2021-07-19T08:08:21Z")

</div>

- if this is a user widget

 ![344457-screenshot-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/6/2/862ea64d852ef34836236bc8806885c1ed1e7c6b.png)

- and this is the parent container hosting those widgets:

![344458-screenshot-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/d/a/cda807d5b20fa4d9c0877954784a1ec5277393de.png)

Set the instance’s data to have said instance take a different execution path. Or use a select node to feed other elements pertinent data. Here, providing each user widget was given a different ID, that widget would take a different execution path.

* * *

There are betters ways than using an int, ofc - enumerators are much more descriptive & human-readable, for example.

* * *

Another, slightly more advanced technique that does not require you to encapsulate the functionality within the user widget is to Dispatch the ID.

- the child dispatches its ID (here, an Instance Editable enum):

 ![344459-userwidget2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/b/b/9bb82c8da869652b688260bb2012415544f56e84.png)

- only to have it caught by the parent:

 ![344460-parent2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/9/e/b9ed8f1cf6f5d8765b5bef4ebc09659c5062d660.png)

Now you can create a bazillion of generic light-on-script widgets that do know what they’re executing; it’s decided by the underlying, owning widget instead. Only the parent needs to know about the functionality.

Optionally, at the bottom, one can manually set up dispatchers if so preferred.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3ad9ae12](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3ad9ae12](https://forums.unrealengine.com/u/anonymous_user_3ad9ae12)\
**Post date:** [July 19, 2021, 1:02pm UTC](https://forums.unrealengine.com/t/override-child-widget-function-event/486359/5 "2021-07-19T13:02:24Z")

</div>

Thank you so much! That isnt quite what I was hoping the answer would be, but It’s still very helpful and I’ll try it! Thank you again so much!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 19, 2021, 2:03pm UTC](https://forums.unrealengine.com/t/override-child-widget-function-event/486359/6 "2021-07-19T14:03:47Z")

</div>

Perhaps consider rephrasing it one more time.

> I have a function called  
> “ButtonPressed”, called when the  
> button within the source widget is  
> pressed, the behavior of which I want  
> to customize for each instance of the  
> source widget within “Widget1”. Thank  
> you so much for your answer;

For example, what does it mean to _customise the behaviour_? This sounds very much like what I originally posted. The base class has a function and the inheriting children override it with their own versions. Each child would be able to handle it differently providing they’re of different class.

* * *

Perhaps your have [Interfaces](https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/Blueprints/UserGuide/Types/Interface/UsingInterfaces/) on your mind, where unrelated classes can talk to each other via a set of functions declared in the Interface.

- the player interacts with various actors in the scene by pressing E
- press E on the tree, Shake the tree, apples fall
- press E on the medkit, Use the medkit, health goes up
- press E on the bucket, Kick it, we’re dead

Here _Shake_, _Use_ & _Kick_ are interface functions and the target object decides how to implement _any_ of them. From the player’s perspective they _just interact_ in the same way, but the end result depends on the target actor.
