How to display needs (hunger, thirst, etc) % in text form?

I know how to display text based on a widget such as a progress bar. However, I am looking to change text in an image based on the value of the need, without something such as a progress bar. Attached is a snip of the images I a, using. The text boxes are to the right of the icons within the circle images.

If you want % numbers to appear in the circle next to those icons, I think you need to have a different texture for each %.

If you want to see [knife&fork 10%], then [knife&fork 20%]… etc, you need a texture for each percentage.

( Correct me someone if I’m wrong ).

Ah, I was wrong see, haven’t done any HUD stuff yet… :-/

if you just want to show a number and percentage as text then add a text component to each circle, then create a binding for the text value. in the binding get the value / number you want to display then append to it a percent sign.

also please dont create duplicate threads you asked the same thing at the link below

Depends on how you are handling your stats, but one approach you can take is binding a function on your UI to update Text boxes whenever a stat (hunger) is changed with division of hunger current vs hunger max variables.

the below pictures show an example of working toward your aim. to begin add a text component to your widget. next with it selected, in the details panel locate content, then text, then click bind then create binding. the next thing we will need is a reference to the player or wherever you are storing the values to be displayed. i used the player character in this example so on event construct i get player character, then cast to the identify it, then i save this reference to a variable named player. now we need to script the binding which should be shown in your functions list if it was created earlier. for this script we simply get the player reference, then get the variable from the player that we want to display (health in this case), then the last thing to do is to add the % sign which i did through a append node.

note there are other methods to set the text value but this is a good place to start. also once a reference to a actor has been saved as a variable you can create direct bindings to variables that are the same type as your trying to bind to. for example if your binding text and you have a text variable in the player then it will show below the create binding option.

Awesome thank you! Also, I kept getting an error when trying to post it so I didn’t mean to have duplicates. Thank you for bringing that to my attention.

I would only put things on a binding if it’s going to change often enough that you would put it on a Tick in another situation. Otherwise, whatever code is causing the change to your variable (say, Hunger for example) might be called way more often than necessary.

I started setting up all of my UMG widgets with bindings but really I found it better to just call the change from elsewhere.

I usually create functions in my widgets which handle updating their text, and then just call the function on the relevant widget when something with UI tied to it gets updated. For example, in your code (or ideally your function) where you change the player’s hunger, just add a reference to your UI class which contains the text for the percentage then use the Set Text node on the widget component.

From what I understand this is much more efficient and bindings are better left for variables in your game which are changing very often or need to be very accurate.

On a side note, when I wanted to get a percentage and display it as one in my UI, I just took the raw values and converted them in to a percentage.

CurrentValue / MaxValue will give you the percentage as a decimal, then you can just multiply the result by 100 and you have your percentage, just append a %.

i generally agree with what your saying, i usually use similar approach to the functions you mention. however from my experience bindings seem a easy way for beginners to get the basic idea and get their ideas up and running. so it may not be optimal but its one way to get it done. also it doesn’t require getting a reference to the widget which many people starting out don’t understand in the least.

That’s fair, I’m not sure how I feel about encouraging a practice because it’s the easy way (unless it’s of course appended with the idea that it’s not the optimal way) as it can lead to bad habits. Thanks for your reply Thompson!

who’s to say whats optimal? what if there’s a simple game (not taxing on the system) and theres many things that can affect a value, the time commitment to call a function or get references may not be worth it if the performance impact doesn’t affect gameplay.

personally i’d like to go with your solution is valid and the one i presented is too, it just depends on the situation.

Thanks a bunch! Thompson is right, I am a beginner so that is a little more of an advanced topic for me. I do understand bindings. However, I am open to learning skus proposed idea. I’m going to look into it more!

Probably a noob question (I just started converting from unity to unreal this past week), but what is between append and health?

I believe Skus was explaining something like the below example. I’m using health in this example but you could use it for many things. as you can see at the top of the picture, in the character we have the event any damage which is executed as you expect when damage is applied. so the event gets called and we modify the health variable in the character but it doesn’t automatically update the ui in this case since we aren’t using bindings. instead we need to tell the ui to update so get a reference to the widget, cast to identify it if need be (may not need to cast depending on how you got the reference), and finally call a custom event in the widget update health which i added a input parameter to so we can pass on the new value. now in the widget is the custom event and when its called it takes the new health value and converts it to text and sets the text value of the text component. of course there can be variations of this implementation as well.

the reason this is more performant generally; is that it only updates when you tell it to as opposed to a binding which basically updates itself every frame even when theres no need.

thats a converter node. it converts from a float to a string. you can do a search for something like float to string and it will show up or you can usually just drag from the green pin to the magenta pin and a converter will be created automatically. also converters exist for many pin types (most basic types) though there are a few that either don’t have a converter or the auto create isn’t implemented.

Thank you so much! I learn better with visuals rather than just words themselves.

So for instance, if I am creating an event for hunger change, can I break it into Degen and Regen (as in the photo)? Or should I have separate events for each? What would be the best choice for optimization/readability of blueprint (if it can be broken into Degen and regen from hunger change)?

you could just use one event and one input if you wanted. then when you call the event you just input how much to decrement or increment the hunger value.

or again using one event you could have a bool input that tells if the hunger change is positive or negative and if negative multiply the input value by -1.

Opinion: when it comes to one vs two events in this instance it wouldn’t be a big issue performance wise since its so few nodes and i imagine it won’t be called a ton. as for readability well that’s subjective but to me i’d think one event would be easier to keep track of and modify if needed (no duplicate script). that said where you call the events maybe a little harder to keep track of (two of the same event but with one being say +1 and the other -1).