Download

Extending UUserWidget

Is there a simple tutorial that shows how to extend UUserWidget where it repaints itself in the UMG designer window?

I have followed a few tutorials including Hello Slate (https://wiki.unrealengine.com/Slate,_Hello), plus two from WCode: (https://wiki.unrealengine.com/UMG,_How_to_extend_a_UUserWidget::_for_UMG_in_C%2B%2B.) and (https://wiki.unrealengine.com/Extend_UserWidget_for_UMG_Widgets).

After creating my C++ class that extends the UUserWidget, I can see the custom widget properties in the Graph Edit -> Class Defaults. But when I try to add the widget to another widget it doesn’t render. Am I missing something?

I have the constructor, and Construct_Implementation:



UKeyboardButtonWidget::UKeyboardButtonWidget(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP)
{
}

void UKeyboardButtonWidget::Construct_Implementation()
{
    Super::Construct_Implementation();
}


Do I need to implement OnPaint()? Or something else?

Thank you for the help.

It’s not clear what you’re expecting, or what you’re trying to achieve. For what purpose are you extending UUserWidget in code?

You need to override NativePaint (or whatever it’s called in the version of UE4 you are on) only if you want to draw custom slate primitives directly.

If you’re trying to make a new kind of slate widget, make a Slate widget, and just wrap it with a UWidget. UuserWidgets are only intended for users making a user control in the designer, inheriting from it is mostly only supposed to be if you need to provide some native code behind for your specific user widget you plan to make in the designer.

Actually, yes, I am trying to make a widget that can be used in the designer similar to the Common controls: Button, Check Box, Image, etc.

When I create a class based on UUserWidget it shows up in the designer but doesn’t render. However, I haven’t found how to get a slate based class to show up in the designer.

EDIT:
I can edit slate derived objects in the Generic Asset Editor.

Any class derived from UWidget (but not UUserWidget) will show up in the designer. As Nick says, you should make your widget implementation in Slate (usually derived from SLeafWidget) and then create a UMG UWidget wrapper around it.

Just look at the existing widgets in the engine source code. SImage/UImage is a pretty simple example, I used it as a reference when I started making custom widgets.

SCompoundWidget for most widgets. SLeafWidget if it can’t have children (Text, Images). SPanel for new kinds of layout panels, like SCanvas…etc

That’s good to know. . .I couldn’t find UWidget.

I’m sorry. . .I haven’t connected the dots yet. In HelloSlate the HUD instantiates the SCompoundWidget. The same is true in SlateTutorials but the two tutorials use slightly different methods: SNew as apposed to SAssignNew. I suspect they are similar in functionality though.

Regardless though, my SCompoundWidget derived class isn’t viewable in the UMG designer. What do I need to connect to it in the designer?

Once you’ve made a Slate widget you need to wrap it with a UWidget. Slate isn’t UObject based, so it needs to be wrapped by one to be accessible to blueprints…etc. For examples, see any of the numerous controls in the UMG module, UImage, UButton…etc. Then it will show in the palette.

For starters I’d like to inherit from UButton. And after looking at the sources:

https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/UMG/Public/Components/Button.h
https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/UMG/Private/Components/Button.cpp
:
https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/UMG/Public/Components/ContentWidget.h
https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/UMG/Private/Components/ContentWidget.cpp
:
https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/UMG/Public/Components/PanelWidget.h
https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/UMG/Public/Components/Widget.h
https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/UMG/Public/Components/Visual.h

I created a C++ class based of Visual : Widget : PanelWidget : ContentWidget : Button in the Add C++ Class dialog box. Unfortunately UContentWidget isn’t recognized, and oddly enough Visual Studio cannot open the ButtonWidgetStyle.h header file.

Do I need to set an include path? That doesn’t seem right.

Adding “UMG.h” fixed the unresolved issues :slight_smile:

Okay, what I was trying to do may be easier than I thought. Basically after inheriting from UButton I am able to add additional properties and see the derived control in the UMG Palette:

CustomButton.jpg

Now I just have to work out the additional functionality :smiley: