How to add a "Widget" in a extended UUserWidget.

After extending a UUserWidget class and set it to the parent class in the WidgetBlueprint.
How can i add a new member to that Widget as i whould a component for a actor?

What are you trying to add exactly?
Are you trying to force a slate widget to always be on the root widget on your UserWidget?

If so why? The whole reason to use UMG is to allow layout to be done easily, locking in the root widget seems to be a big restriction.

Can you provide a bit more information so I can understand what you are trying to do , I’ve been playing a bit with UMG and Slate in C++ lately.

Basicly i want to make the variabels/ Widgets in C++.
And when i go into the editor i want thos to be visible and available for edit.
By default it has Root > Canvas Panel

So i whould like to have e.g:
Root > Canvas > Border

The resson for this is to have the mebers available in the extended user widget and available in code.

EDIT: Also this is on a related note with code and UMG/ User Widget.

I am not sure you can really easily force widgets onto the scene without changing engine code.

Alternatively you could though manually add the widgets you want in UMG and then catch them in code and do things with them.

I have started doing this in places in our code now. I wrote a menu slate widget (and UMG version) to handle lots of common stuff we needed and my extended UserWdiget class searches for the first widget with this type and binds to it.

I do this in RebuildWidget, after the super.

 TSharedRef<SWidget> USubmergedOptionsMenuUserWidget::RebuildWidget()
     TSharedRef<SWidget> OurWidget = Super::RebuildWidget();
     for (UWidget* Widget : Components)
         if (Widget->IsA(USubmergedMenuWidget::StaticClass()))
             //found it now do whatever you need to it, store the pointer etc
     return OurWidget;

I do this so that we can put our menu widget in any layout choice we want without me having to change code. But once they added it I then can change anything else I want. I progamatically add the relevant menu items, what to do on the click op options, what the keyboard/controller/touch input mean, handle the localization etc.

This approach might help you , sure you have to manually add the widgets you want, but since you probably only have to do this one or twice, its usually not too bad a headache.

Let me know if this is helpful at all and if you want any more information about what I have done.

See if the answer helps, as for the forum question, I posted a reply there on how to fix the crash you are getting.

Edit: In case they dont approve fast enough, the trick for the crash is to always remove the delegate first, I do this all the time and it will just do nothing if it isnt bound. I saw epic were doing it in examples. So go RemoveDynamic first

Great that worked like a charm :smiley:
Am testing the answer aprichiate the help.

No worries at all, post any questions re the answer below it :slight_smile:

Obviously if you have many items of the same type you can match by name, I do that in places too.

Sorry for late reply sometimes the schedual get the better of me.
This was very helpful so thank you very much i decided i was over complicating stuff a bit. But none the less this is going to be very nice to know about down the line as well.

The API has been changed a little. You can no longer iterate through the Components this way. You can get the widgets by calling WidgetTree->GetAllWidgets(TArray& OutWidgets).
You also must make sure that you added the private dependencies for Slate UI, otherwise the WidgetTree is inaccessible. Just uncomment the PrivateDependencyModuleNames.AddRange(new string[] { “Slate”, “SlateCore” }); in the [ProjectName].Build.cs

1 Like