How to create C++ based UMG in UE5 onwards

So, it’s been a while since I touched the C++ side of UMG creation, and it seems a lot of things changed now in UE5. One important one being that UMG doesn’t automatically come with a canvaspanel as a root widget. In fact, there is no default root widget at all.

Which is fine, I guess, but I need a reference to the root widget so I can properly generate all of my other elements in my UI, something I would prefer very much not to do in blueprint. So how can I set up the root widget through C++? I have tried to use RebuildWidget, but that one just crashes the whole thing.

Right now, I can use the approach where I set all the elements up in NativePreConstruct, add a root widget in blueprint (since adding it there will actually cause the root widget to be registered), which in turn will automatically add all the elements I defined in the NativePreConstruct. However, this just feels hacky; I would prefer to set up the root component in the code as well.

1 Like