Create UMG Button from C++
I am trying to create a UMG button (UButton) inside a verticalBox from C++ and make it appear inside the canvas of the UMG Widget I created as BluePrint. I have googled up and down and can't find a single working example, neither for creating a UMG built-in type in C++ nor for displaying the created widget in the world.
asked Feb 25 '15 at 11:38 AM in C++ Programming
I was having trouble figuring out how to do this in my widget I inherited from UUserWidget. Eventually figured out I needed to do a few casts, like casting GetRootWidget to a panel widget so I could add a child, and casting the result of that to a UCanvasPanelSlot instead of a normal UPanelSlot so I could set the position and scale information.
Here's a code snipped in hopes that it helps someone...
answered Mar 30 '16 at 11:45 PM
This worked well for me when I wanted to add it to an existing Panel
answered May 22 '15 at 11:08 AM
you can create a widget in code with the global namespace "CreateWidget" call.
I do not know, if CreateWidget works with a native UButton, but you could also workaround this, by creating a UUserwidget out of a widget-blueprint which has a nested UButton in it, and adding this widget to your parent.
The UButton from your created UUserWidget instance can be accessed, if you know the name of your button:
UButton* pButton = (UButton*)pButtonWidget ->GetWidgetFromName(FName("Button"));
The property ButtonTemplateWidget could be declared in the header, so it can be set from the editor if your class is derived from UObject:
Hope this helps!
answered Mar 01 '15 at 02:03 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here