UMG, How to extend a UUserWidget:: for UMG in C++.

From Epic Wiki
Jump to: navigation, search


Author: WCode (talk)

A updated version of this tutorial can be found here.

I wanted to extend the Widget Blueprint, i got some great help from Nick Darnell so thanks again.

In order to derive my class from UUserWidget:: i did the following.

Add Header Files To Project

You add several headers to your project header. "(YourProjectName.h)".

#include "Runtime/UMG/Public/UMG.h"
#include "Runtime/UMG/Public/UMGStyle.h"
#include "Runtime/UMG/Public/Slate/SObjectWidget.h"
#include "Runtime/UMG/Public/IUMGModule.h"
#include "Runtime/UMG/Public/Blueprint/UserWidget.h"

Adding Modules

And then i also made sure that the UMG and Slate Modules was included as well. In "(YourProjectName.Build.cs)":

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "Slate", "SlateCore"})


Compile and re-open the editor. And add a new class to the project derived from UUserWidget::

If you were wondering how the header of the derived class looks like after created/ added from the editor.

#pragma once
#include "Blueprint/UserWidget.h"
#include "InventoryWidget.generated.h"
class MYGAME_API UInventoryWidget : public UUserWidget

Using the new User Widget class

Create a new Widget Blueprint as shown in the image. UMG1.PNG

Set the Widget Parent

Open up the new Widget you just created and go to the Graph of the Widget Blueprint. Press on the UMG2.PNG button on the top of the window.

Go down to the details

Under the Category "Globals" you set the class you derived from UUserWidget. UMG3.PNG


You are done, now you have a simple and fast way to extend the user widget. From everything from Data Storage to picking up "events" delegates and so on.

Hope this was helpfull.


Related Tutorials

[Updated Tutorial] Extend UserWidget for UMG Widgets by WCode.

Epic's UMG Documentation

UMG, Create Scrollable List of Clickable Buttons From Dynamic Array, by Rama!

[Tutorial/ Snippet] Creating a UMG Widget in C++, and delegate example by WCode.