# Get root widget of UMG in blueprints?

**URL:** <https://forums.unrealengine.com/t/get-root-widget-of-umg-in-blueprints/364290>\
**Category:** UI\
**Tags:** unreal-engine, UE4, question, Blueprint, UMG\
**Created:** [July 17, 2016, 3:51pm UTC](https://forums.unrealengine.com/t/get-root-widget-of-umg-in-blueprints/364290 "2016-07-17T15:51:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![MothDoctor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mothdoctor/32/1194551_2.png) [@MothDoctor](https://forums.unrealengine.com/u/MothDoctor)\
**Post date:** [July 17, 2016, 3:51pm UTC](https://forums.unrealengine.com/t/get-root-widget-of-umg-in-blueprints/364290/1 "2016-07-17T15:51:51Z")

</div>

I’d like to get the very first element placed in User Widget. When I get it, I can search children (all included widgets) fully dynamically. Is it possible to get this root in blueprints?

AFAIK I could achieve it in C++ by calling GetRootWidget(), right?  
But I’m preparing blueprint only package in order to give it to community. I’d have to create code plugin for one function call if there’s no way to get this information in blueprints 😉

---

<div class="post-metadata">

**Author:** ![fabianu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fabianu](https://forums.unrealengine.com/u/fabianu)\
**Post date:** [July 18, 2016, 1:00pm UTC](https://forums.unrealengine.com/t/get-root-widget-of-umg-in-blueprints/364290/2 "2016-07-18T13:00:57Z")

</div>

Yes it is with a little workaround.

I create a sample widget with the following structure:

![98934-widget1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/f/9/5f9e9bfe211fbadd5ef495523141195396977f6f.jpeg)

It has a root component (which you want to access) and 4 childrens.  
Then click the root component and check the “Is Variable” checkbox in its details panel.

![98937-widget2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/f/c/0fca41a5ab773227b254199ba31d00e8d1678965.jpeg)

Now go to the widgets graph tab and the root component is accessible as a variable and can used as you wish:

![98940-widget3.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/9/f/c9f29c11d930205277dad1aac156e39627d3981b.jpeg)

---

<div class="post-metadata">

**Author:** ![MothDoctor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mothdoctor/32/1194551_2.png) [@MothDoctor](https://forums.unrealengine.com/u/MothDoctor)\
**Post date:** [July 18, 2016, 1:31pm UTC](https://forums.unrealengine.com/t/get-root-widget-of-umg-in-blueprints/364290/3 "2016-07-18T13:31:20Z")

</div>

Yes, it would work if I’d apply script in every asset 🙂  
But I’m looking for way to get root without referencing to any specific variable, just get it dynamically.  
Let’s say I got PanelBase and every other panel is child of it. I call “Get Root Widget” only in PanelBase without knowing what’s inside of children.  
Well… it looks like I need to put C++ function into plugin.

Still, thanks for help! 🙂

---

<div class="post-metadata">

**Author:** ![fabianu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fabianu](https://forums.unrealengine.com/u/fabianu)\
**Post date:** [July 18, 2016, 2:00pm UTC](https://forums.unrealengine.com/t/get-root-widget-of-umg-in-blueprints/364290/4 "2016-07-18T14:00:49Z")

</div>

I think then c++ is the only way. Have a nice day!

---

<div class="post-metadata">

**Author:** ![EvoPulseGaming](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EvoPulseGaming](https://forums.unrealengine.com/u/EvoPulseGaming)\
**Post date:** [January 3, 2018, 9:48am UTC](https://forums.unrealengine.com/t/get-root-widget-of-umg-in-blueprints/364290/5 "2018-01-03T09:48:43Z")

</div>

Here is what I did (Blueprints!)

1.Create a Blank UserWidget named Menu\_Base

2.Open Menu\_Base and in designer delete the default CanvasPanel\_0 (errors and warnings if you dont!)

3.Open Graph and create a variable called Root\_Panel\_Widget of “Panel Widget” type  
Make sure to set this as VISABLE (The little eye needs to be Yellow)  
(Panel Widget is the base class for all containers that can have children!! i.e canvas,border, grid ect)

 ![225779-2createvandsetvisible.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/9/6/d964d55d1c92b80e065a9a81f7c2febeb2425735.png)

4.Compile and save and close this, we are done here.

Now for some reason you cant right click and use “Create Child” on Menu\_Base, so:

5.Create a Blank UserWidget and open (or use an existing UserWidget you’d like to remap)

6.Click on the FIRST Child in designer and select IS VARIABLE to True (CanvasPanel\_0 in a new widget)

 ![225780-3makevis.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/0/d/40d1834834273f559c685d889806493eea74070d.png)

7.Open Class Settings, and change the parent class to Menu\_Base  
8.In this widget get your Event Construct, and set Panel\_Widget\_Root as CanvasPanel\_0

 ![225781-menubase.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/0/b/c0b9e8ce77dada40e0e02870cdcf960b84abf3f2.png)

9.Compile and save.

Now you can use Panel\_Widget\_Root at runtime and call Get Children!!!

Here is my fancy function (has to be a function, do not use as an event! (breaks the loops) that changes ALL buttons and checkboxes for a uniform appearance across the whole game, this also allows the user to choose pre-selected images for personalizing their own preferences!  
I have a Widget that has a SwitcherWidget that contains ALL menu/settings/lobby/char selection ect widgets  
Some of the sub Widgets also have SwitcherWidgets!

 ![225783-masterplan.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/c/1/6c1ce1ad5a204ddce7afb79a5259cae0fba66da0.png)

Here is the result!  
The Back/Quit buttons are default, the rest are changed at runtime!  
If I want to change the appearance, I make ONE function call on the root UserWidget and done!

 ![225784-examplss.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/4/d/14d5150363963ef518b94199d0ca0333a0edcc45.png)

---

<div class="post-metadata">

**Author:** ![EvoPulseGaming](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EvoPulseGaming](https://forums.unrealengine.com/u/EvoPulseGaming)\
**Post date:** [January 3, 2018, 9:54am UTC](https://forums.unrealengine.com/t/get-root-widget-of-umg-in-blueprints/364290/6 "2018-01-03T09:54:07Z")

</div>

The beauty with UE4 is the Parent/Child Object Oriented system. If you just know how to create the container in BP, you can get around almost all missing Parent/Child functionality.  
Look at my answer below for my answer/example.

I used a similar parent/child “container” system to map “modules” to meshes on my character (to extend Mesh functionality, such as armor, damage, cooling system) by attaching “child actors” to each mesh and setting them at runtime.

---

<div class="post-metadata">

**Author:** ![EvoPulseGaming](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EvoPulseGaming](https://forums.unrealengine.com/u/EvoPulseGaming)\
**Post date:** [January 3, 2018, 9:58am UTC](https://forums.unrealengine.com/t/get-root-widget-of-umg-in-blueprints/364290/7 "2018-01-03T09:58:10Z")

</div>

p.s created in 4.18  
Not sure when this changed, but as of 4.20/21 you have to add “Add Call to Parent” on the “Event Construct” of each child or this wont work (you add this call after the childs event construct

OR  
In the children, move the set panel root to the PRE construct part, and make sure you delete the empty Event Construct (or add the parent call if you have other code here)

---

<div class="post-metadata">

**Author:** ![HungryHenry](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hungryhenry/32/722352_2.png) [@HungryHenry](https://forums.unrealengine.com/u/HungryHenry)\
**Post date:** [April 11, 2024, 2:08am UTC](https://forums.unrealengine.com/t/get-root-widget-of-umg-in-blueprints/364290/8 "2024-04-11T02:08:36Z")

</div>

For anyone in need of the “Get Root Widget” function in blueprints, especially in the dynamic widget tree where assigning manually isn’t practical, here’s a recursive function inspired by “BDC\_Patrick 🇩🇪🇬🇧🇺🇸” from the Discord community.  
I have tested it. Started from Image. Got the CanvasPanel. Not the Top “CustomUserWidget” as I expected. But this might be handy for you.

 ![Snipaste_2024-04-11_10-01-53](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/f/6/0f6cc852b8e521afc14026d347799716b3f303ba.png)

In case of the image not loaded properly:

```auto
UUserWidget* FindRootWidget(UUserWidget* CurrentWidget)
{
    if(!IsValid(CurrentWidget->GetParent())){
        return CurrentWidget;
    }
    return FindRootWidget(CurrentWidget->GetParent());
}

```

---

<div class="post-metadata">

**Author:** ![STRiFE.x](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/strife.x/32/969826_2.png) [@STRiFE.x](https://forums.unrealengine.com/u/STRiFE.x)\
**Post date:** [July 27, 2024, 5:13pm UTC](https://forums.unrealengine.com/t/get-root-widget-of-umg-in-blueprints/364290/9 "2024-07-27T17:13:08Z")

</div>

This walks up the chain to get the outer most widget (works for widgets inside of widgets).

```auto
UUserWidget* UFPMScreenWidgetBase::FindRootWidget()
{
	UObject* CurrentWidget = this;
	while (true)
	{
		UObject* CurrentWidgetTree = CurrentWidget->GetOuter();
		UObject* TreeOuter = CurrentWidgetTree ? CurrentWidgetTree->GetOuter() : nullptr;
		if (TreeOuter && TreeOuter->IsA<UUserWidget>())
		{
			CurrentWidget = TreeOuter;
		}
		else
		{
			// Reached top level widget.
			break;
		}
	}

	return Cast<UUserWidget>(CurrentWidget);
}

```

---

<div class="post-metadata">

**Author:** ![RHZhang](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RHZhang](https://forums.unrealengine.com/u/RHZhang)\
**Post date:** [March 4, 2025, 1:23pm UTC](https://forums.unrealengine.com/t/get-root-widget-of-umg-in-blueprints/364290/10 "2025-03-04T13:23:39Z")

</div>

There may be a problem. TreeOuter may be a UWidget but not a UUserWidget. In this case, you cannot say CurrentWidget is the root.
