Can I add Slate children to a UMG widget in C++?

Another newbie q here. I have a UUserWidget in my UI, and I’d like to populate it in its Initialize() method with a bunch of children. The children can get kind of complex, but the hierarchy is known at compile time, so I see that Slate has this cool syntax for specifying widget hierarchies. (Slate UI Widget Examples for Unreal Engine | Unreal Engine 5.1 Documentation)
So my question is, given I have a UMG widget called root which is a UMG UWrapBox, can I add Slate children to it? I see that UWrapBox->AddChildWrapBox() takes a UWidget*, but I don’t think I can convert a SWidget to a UWidget. Am I just out of luck, so I need to keep going all the way down to the low-level text boxes and buttons with UMG? No big deal if so, I just like that “too clever” Slate syntax.

I see i got you interested :stuck_out_tongue: You need to create your own UWidget that contains 1 or more Slate widget, so insted of using UWrapBox in UUserWidget, use SWrapBox in UWidget. In RebuildWidget() you build slate widget with that syntax you linked. then in SynchronizeProperties() you make code that updates Slate widget/s when properties are changed. You can also restructure the widget by calling InvalidateLayoutAndVolatility() which will cause widget to rebuild it self.

Again look up the source code of exiting UMG widgets:

https://github.com/EpicGames/UnrealEngine/tree/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Runtime/UMG/Private/Components

Most of them are just wrappers of Slate widgets, they very simple so it should be easy for you to understand. UMG are made of slate widgets so most of them has slate euivlent, look up on tree here:

and this is probably what you probably want to use:

If you look on bottom part refrence there FArgument and FSlot. Those are arguments used for that syntax FArgument is parameters for entire widget and FSlot are augments for a slot of widget:

Also remeber to override GetPaletteCategory() functrion to set category of UMG widget in editor, if you dont do that your widget will be in “Uncategorized”.

Also importent thing is fact that RebuildWidget() is called in widget blueprint editor, so you should not call any gameplay code in there. you can check if your widget is either in editor or in gameplay by using IsDesignTime() function. So check if IsDesignTime() is false before calling any gameplay code. This also allows you to make widget apperence diffrent in eidget editor and in gameplay.

Slate API are outside of UE4 reflection system and UE4 don’t see what happening in there, that why they are not usable with blueprints and there for UMG was made to wrap Slate widgets with UObject classes which can be used with blueprints. There API are not compatible, UMG widget simply build Slate widget and operate them, UMG widget should not communicate directly with Slate widget of other UMG widget, make function in UMG widget that will call function in slate widget which other UMG widget can call, besides there no other way to do call function to Slate in blueprints.