Hey all,
I need to be able to create a UWidgetComponent at runtime through C++, and I can’t seem to figure it out. I have tried using CreateDefaultSubobject, but it just crashes. I have also tried AddComponentByClass, and nothing seems to happen.
Hey all,
I need to be able to create a UWidgetComponent at runtime through C++, and I can’t seem to figure it out. I have tried using CreateDefaultSubobject, but it just crashes. I have also tried AddComponentByClass, and nothing seems to happen.
Creating a WidgetComponent is no different than any other component. You can’t use CreateDefaultSubobject for runtime components since those aren’t defaults.
You would just use NewObject to construct the widget and attach it. There’s a more in-depth discussion of details here: Add component to actor in C++ (the final word!) - #8 by HappyHappyPlay