Set SlotSizeRule from C++ code?

From UMG editor it is very easy to set the slotsizerule eihter to Fill or Automatic. But how can I achieve the same via C++?

USpacer* HSpacer = NewObject<USpacer>();
// Do something like: HSpacer.SetSlotSizeRule(ESlateSizeRule::Type::Fill);

Hello! In C++ slots are used in some other way see for example this Slate Widget Examples | Unreal Engine Documentation. After widget pointer follows + operator and then slot object. It is often created by static method, and on that instance you can set every slot property that this slot has.

Hi Kehel18. Thanks so much for your answer. I have seen the page you linked, but couldn’t understand it very well… From what I understood SWidget and UWidget are different, rigtht? Can I change the size rule of a UWidget, for example USpacer?

Widget can be contained in many different container widgets that work in different ways and they can have multiple slots, there for there separate object for slot and it has it own properties. UMG editor for simplicity shows those as a part of widget properties but it’s really isn’t.

You can access slot object use this:

Also each container widget got it own slot class as they are different for each, so you will most likely need to cast