# GameInstance and UMG widgets as Blueprints?

**URL:** <https://forums.unrealengine.com/t/gameinstance-and-umg-widgets-as-blueprints/365918>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [August 2, 2016, 7:12pm UTC](https://forums.unrealengine.com/t/gameinstance-and-umg-widgets-as-blueprints/365918 "2016-08-02T19:12:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_130f67321](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_130f67321](https://forums.unrealengine.com/u/anonymous_user_130f67321)\
**Post date:** [August 2, 2016, 7:12pm UTC](https://forums.unrealengine.com/t/gameinstance-and-umg-widgets-as-blueprints/365918/1 "2016-08-02T19:12:15Z")

</div>

I am thinking whether both GameInstance and any widget I would like to have should be blueprints rather than c++. Issues I could think of when not doing this that way are

1. Designing the actual Widget.
2. Loading and creating a Widget instance on GameInstance, i.e. default menu. (in c)
3. Adding callbacks to specific UI events, i.e. when a button under Widget is pressed.

How would this be done on c++? Also, I can not figure out how to initialize a Blueprinted Widget, containing default menu’s design, I do not seem to be using the corresponding type.

---

<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:** [August 3, 2016, 1:21am UTC](https://forums.unrealengine.com/t/gameinstance-and-umg-widgets-as-blueprints/365918/2 "2016-08-03T01:21:31Z")

</div>

API reference is your dearest friend. Most things you see in blueprints exists in C++, blueprint nodes are very simple C++ bindings, so you do this the same way you do in blueprints, i think you already fimilar with those functions in blueprint:

> **[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.

> **[UWidgetBlueprintLibrary::Create](https://docs.unrealengine.com/5.1/en-US/API/Runtime/UMG/Blueprint/UWidgetBlueprintLibrary/Create/)**
>
> Creates a widget

Only diffrence is in statixc functions in most cases you need to give UWorld\* which you can do simply by using () from any actor

All UMG widgets are inherent from UWidget so look up that class in API refrence:

> **[UWidget](https://docs.unrealengine.com/5.1/en-US/API/Runtime/UMG/Components/UWidget/)**
>
> This is the base class for all wrapped Slate controls that are exposed to UObjects.

The UUserWidget is class of widget blueprint so it’s also importent

> **[UUserWidget](https://docs.unrealengine.com/5.1/en-US/API/Runtime/UMG/Blueprint/UUserWidget/)**
>
> The user widget is extensible by users through the WidgetBlueprint.

Events are normal delegates, you can see them in varables in in button varables:

> **[UButton](https://docs.unrealengine.com/5.1/en-US/API/Runtime/UMG/Components/UButton/)**
>
> The button is a click-able primitive widget to enable basic interaction, you can place any other widget inside a button to make a more complex and interesting click-able element in your UI.

Best way to get access to UI componet of blueprint widget is to create a base class from UUserWidget and make widget bluepritn based on that class, from that you can grab child widgets using APIs inside that class

Now if you want to design widgets in C++ then i don’t recommendd you to use UMG. UMG is just a blueprint wraper of Slate a UI framework that originally was made for editor but it is also usable in game it self. Native Slate, the way it is design it is incompatible with Blueprint system there for it need UMG to exist there as UMG is made for primarly blueprint use. Slate is a lot more efficient to use in C++ then Blueprintified UMG and you quickly understand why when you see it, here is main docs:

> **[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.

Here good tutorial for beginners:

> **[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...

Slate also provides a lot more features then UMG which only selected stuff is binded, you also have access to all widgets, check out the tree in this page:

> **[SWidget](https://docs.unrealengine.com/5.1/en-US/API/Runtime/SlateCore/Widgets/SWidget/)**
>
> Abstract base class for Slate widgets.

But if you plan to involve UMG, then use UMG APIs… or make own C++ UMG Widget to use Slate there, since UMG widget classes are kind of Slate capsules, look up UButton for example (aspecially RebuildWidget function where widget is made):

[https://github.com/EpicGames/UnrealEngine/blob/ab237f46dc0eee40263acbacbe938312eb0dffbb/Engine/Source/Runtime/UMG/Private/Components/Button.cpp](https://github.com/EpicGames/UnrealEngine/blob/ab237f46dc0eee40263acbacbe938312eb0dffbb/Engine/Source/Runtime/UMG/Private/Components/Button.cpp)  
[https://github.com/EpicGames/UnrealEngine/blob/ab237f46dc0eee40263acbacbe938312eb0dffbb/Engine/Source/Runtime/UMG/Public/Components/Button.h](https://github.com/EpicGames/UnrealEngine/blob/ab237f46dc0eee40263acbacbe938312eb0dffbb/Engine/Source/Runtime/UMG/Public/Components/Button.h)
