I created a C++ class inheriting from UUserWidget
called MaterialsBoxW, and back in Blueprint I added one of these to a parent widget. My goal is that the Initialize()
member of MaterialsBoxW will create and add a bunch of children to MaterialsBoxW.
I want MaterialsBoxW to act like (or actually to be) a WrapBox
. But I don’t know how to do that. So far it is just a sort of undefined UUserWidget. How do I “turn it into” a WrapBox? I’ve seen people adding a UPROPERTY(meta=(BindWidget))
on these forums, but I don’t get how that’s supposed to help.
Is the MaterialsBoxW really just a container for widgets rather than a widget itself?
WrapBox is a widget, so simply place UWrapBox in it and then add items to it.
Look up widget class there here, you can use any widget:
UUserWidget is also widget but made for widget blueprint allowing to compose other UMG widgets inside, if you would use UWidget then you create single widget out of Slate but it can be composition of multiple Slate widgets and they be visible as single UMG widget, UPanelWidget is for Slate’s slot widgets (widgets contain other widgets like Canvas or Wrap Box), but same as UWidget you can use slot system different with already existing Slate widgets. You may find Slate easier to use in C++, if you gonna create widget then look up code of existing widgets to see how they are build, they are mostly Slate wrappers so they are not complicates as you may think.
WrapBox is a widget, so simply place
UWrapBox in it and then add items to
it.
I see, that’s sort of what I was coming to myself. You’re saying that UUserWidget
isn’t really a widget itself (it has no look/feel, can’t have children etc.), it’s just a class that can hold widgets, and gets seen by Blueprint.
So just to help others who may come here: I create a UWrapBox
member variable in my MaterialsBoxW
class (call it root_widget
), fill in that member variable by constructing a new UWrapBox
. Something like this, in the overridden Initialize
method:
root_widget = WidgetTree->ConstructWidget<UWrapBox>(UWrapBox::StaticClass(), TEXT("RootWidget"));
WidgetTree->RootWidget = root_widget;
and then add children to it by constructing them and using root_widget->AddChildWrapBox();
.
And thanks for the pointer to investigate Slate (vs. UMG); I’ll check that out.
3 Likes