I have been playing around with UMG since it came out in experimental format, but just got around to trying to tie data binding to a bar (for fun things like health, stamina, etc). UMG was promoted from experimental status with the latest UE4 release, so everything should be working fairly consistently. I spun my wheels for a little bit because apparently I forgot basic numeric properties >.>

To calculate the percentage for the bar, you have to take current <whatever> and divide it by max <whatever>. Basic math stuffs, yeah? The function for the percentage expects a float returned, because that is standard percentage stuff. Well apparently if you architect your variables as integers and ignore the main difference between integers and floats (whole numbers vs. fractions), you end up with a bar that only registers 0 and 100%! Whoops.

Go maths!

Besides that little snafu, I found the data binding within UMG to be extremely easy to handle inside of Blueprints once I figured out the casting I needed to do. I eventually switched to getting my character’s attributes through a Blueprint interface instead of having to mess around with so much casting. I found it much cleaner and easier to work with.

For example, I created an interface and implemented it in my character class like this:

implemented-interface

After which I can easily pull data out in the UMG HUD class like this:

called-interface

The result of the bars on the front end looks something like this:

bar-output

I’ve since created new attribute variables as floats and recreated the workflows (UE4 doesn’t allow you to change data types of variables that are in use anywhere in the Blueprint). I imagine as long as I segregate my interfaces well enough, they won’t become too unmanageable.