Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to make saved componets for UMG through C++?

Used this guide to extend UMG to C++


But I can't figure out how to add any components that show up in the blueprint for the UMG widget. I re-parented it to my UUInventoryWidget . How can I have a UScrollbox that when I open it in blueprint before the game launches its exposed there and I am able to move it around and edit it, yet still have control of it in C++? Its not showing up in in UMG.

I did Components.Add(myScrollBox);

How can I get my C++ component to show up in Root-Canvas-mycomponent. So that i can then fill in the rest in UMG but still have it exposed. For C++.

providing as much info on this as you can would help a lot. Thanks!

Product Version: Not Selected
more ▼

asked Nov 06 '14 at 11:11 PM in C++ Programming

avatar image

134 39 35 40

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hey there,

I have needed to do similar C++ Link to a widget in my own UserWidget class. I didnt try to add it through code however as I would prefer to have the flexibility of changing the layout at any time.

Instead what I do is match the class and/or name of the item in RebuildWidget(). I call super first to make sure all the widgets are made and then match it and use the widget. Here is an example where I just match the class (I made a special menu UMG and Slate class)

 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;

What this let me do, is then programatically add menu items to our menu widget here and control all input and functionality in c++. But it also lets us put that widget inside any layout controls like vertical boxes etc in UMG and thus non programmers can just move it around.

Of course I am totally reliant on it being added manually to make it work, but I felt that was ok for the flexibility of layout. On a side note, putting it in RebuildWidget means that code also runs in UMG. So be careful, things like the player owner are not set. The bDesignTime flag is your friend here.

Each UWidget class has a function on it to then get the actual slate widget, so you can then do whatever you want!

Let me know if you need any more info

more ▼

answered Nov 10 '14 at 06:05 AM

avatar image

496 18 27 142

avatar image Ben.Driehuis Nov 18 '14 at 03:29 AM

Got your comment via email, but cant see it here atm. But the answers are:

Where/How would you forward declare RebuildWidget? - This is a function on UUserWidget, just override it in your derived class. Make sure you are including the relevant slate classes in your derived class header. This is what have (but I also do some slate animation handling)

 #include "Runtime/UMG/Public/UMG.h"
 #include "Slate.h"
 #include "WidgetAnimation.h"
 #include "UMGSequencePlayer.h"

No need to call it, it happens automatically and happens in both the design view and at runtime once you create it

avatar image CJ31387 Nov 18 '14 at 03:31 AM

How do you implement that. Where do you put that rebuild function and call it?

avatar image Ben.Driehuis Nov 18 '14 at 03:38 AM

If your UUInventoryWidget is based on UUserWidget, then you do in that class:


 class UUInventoryWidget : public UUserWidget
     virtual TSharedRef<SWidget> RebuildWidget() override;

You won't need to call it, Rebuild Widget is the function the UMG system uses to create the slate widgets from their UMG classes. Just make sure you write your code after the Super like in my example earlier.

avatar image CJ31387 Nov 18 '14 at 03:48 AM

Its not happening automatically and I don't know why. Construct() also does not run automatically.

avatar image Ben.Driehuis Nov 18 '14 at 03:56 AM

How are you opening/creating the widget?

What version are you on?

Is it happening in the UMG Editor Preview?

We are creating our via the player controller like so:

 < - Header ->
 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = UI)
 TSubclassOf<UUserWidget> WidgetTemplate;
 UUserWidget* WidgetInstance;
 <-  CPP ->
 WidgetInstance = CreateWidget(this, WidgetTemplate);
avatar image CJ31387 Nov 18 '14 at 04:05 AM

Using 4.5

The widget is a umg blueprint that derives from my class UInventoryWidget

Its working now I have a UE_LOG printing through it but, how would I change all the texts names? Widget only has access to tooltipname, when i try to change tooltipname nothing happens.

But it is printing my log in the for loop when i choose a button or anything that's in my widgettree.

Just trying to figure out how to modify stuff like maybe rename every object to 1 name just to test.

avatar image Ben.Driehuis Nov 18 '14 at 04:20 AM

Excellent :)

The next question depends on what you are trying to edit exactly. What are these text names? What type of widget?

The basic answer is that the UWidget of the type you want, will have functions and a protected pointer to the actual slate widget, which if you get access to (maybe by extending the class or writing your own custom UWidget class), then you can do everything you could in slate.

What I have done is wrote a custom Menu Widget as both a slate and UWidget class. This class has data/functions to let me tell it what all the menu options are and bind delegates to them. So the my custom USerWidget classes find this widget and fill in whatever menu options they want.

Without knowing exactly what widgets you are dealing with and what exactly you are trying to do c++ side, its hard to know exactly where to point you. So let me know some more info and I'll try and help

avatar image CJ31387 Nov 18 '14 at 04:28 AM

Ok got it, I just cast to the widget type in the for loop and modify specific members. Thanks!

avatar image CJ31387 Dec 12 '14 at 07:06 PM

Did this change in 4.6? Getting Unidentified in for (UWidget* Widget : Components) at components

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question