# How can I get a reference to my Widget?

**URL:** <https://forums.unrealengine.com/t/how-can-i-get-a-reference-to-my-widget/354297>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [April 15, 2016, 1:14pm UTC](https://forums.unrealengine.com/t/how-can-i-get-a-reference-to-my-widget/354297 "2016-04-15T13:14:28Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [April 15, 2016, 4:43pm UTC](https://forums.unrealengine.com/t/how-can-i-get-a-reference-to-my-widget/354297/2 "2016-04-15T16:43:04Z")

</div>

Ah so you want to find a widget blueprint. First of all i need to tell you that blueprints are classes same as C++ classes, they inherent the same way, i explain that in this video

Now widget blueprint is standard blueprint, blueprint it self is asset which contain blueprint code which is used to generate the class added to hierarchy together with C++ classes.

So first get widget blueprint class is UWidgetBlueprint and oyu get it same way as that mesh and to get UClass of widget from blueprint asset you use GetBlueprintClass()

> **[UBlueprint::GetBlueprintClass](https://docs.unrealengine.com/5.1/en-US/API/Runtime/Engine/Engine/UBlueprint/GetBlueprintClass/)**
>
> Gets the class generated when this blueprint is compiled.

But UClass is just class identifier, you need to spawn widget:

```
UClass* ClassFromBlueprint = WidgetAsset->GetBlueprintClass();
UUserWidget* Widget = NewObject<UUserWidget>(this,ClassFromBlueprint);

```

And then you just add it to viewport with this function liek yiou do in blueprints:

> **[UUserWidget::AddToViewport](https://docs.unrealengine.com/5.1/en-US/API/Runtime/UMG/Blueprint/UUserWidget/AddToViewport/)**
>
> Adds it to the game's viewport and fills the entire screen, unless SetDesiredSizeInViewport is called to explicitly set the size.

There simpler way to do this, make UPROPERTY settable in blueprint with

```
TSubclassOf<UUserWidget*> 

```

type, in class like AGameMode, then you create GameMode blueprint based from that class and you set that varbale, then you spawn widget based of that varable (note TSubclassOf is UClass\* which limits class selection in editor). This is more nice looking solution and safe from any potential refrence issues in packageing

Also importent node, UMG is blueprint frontend for Slate (UI framework original made for editor, but it is used also in UE4 gameplay, UMG let it use it in blueprints), Slate in raw form is a lot nicer to use then UMG in C++, so if you want to define UI in C++, Slate is better:

> **[Slate UI Programming](https://docs.unrealengine.com/5.1/en-US/slate-user-interface-programming-framework-for-unreal-engine/)**
>
> Program user interfaces with Unreal Engine's Slate framework.

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

---

_[View the full topic](https://forums.unrealengine.com/t/how-can-i-get-a-reference-to-my-widget/354297)._
