I’m trying to create a health bar that’s scale X changes based on the character’s level. How do I access the size of a progress bar via C++ and change it so that it can be updated while playing?
Assuming you have the refence to the UProgressBar and have calculated the percent progress:
UProgressBar* progressBar;
Update the progress like this:
progressBar->SetPercent(percent);
Docs:
UProgressBar | Unreal Engine 5.4 Documentation | Epic Developer Community (epicgames.com)
Use a size box. Make the progress bar a child of the size box, and then calculate the percent of your progress bar however you want it.
The size of the progress bar not the percentage it’s filled to
How is the size defined in the first place ?
If it’s placed in a Canvas Panel, with a fixed size defined, you can change it by accessing its slot as canvas slot (Widget->SlotAsCanvasSlot) and modifying the size there.
Alternatively if you wrap it in a size box with a fixed WidthOverride, you can easily modify that too.
It’s not defined at all at the moment LOL. I’ve yet to design UI using C++ at all so I’m not sure where to start with what header files to include and classes to use but this puts me in the right direction.