How can I make it so when I get my a tooltip on screen it only shows certain stats? I'll explain more

So what I want to do is, I have an Item info struct, Datatable, etc. and I have certain item with certain stats. and when I hover over and get a tooltip I only want the stat to show that is greater than 0 with the Text/amount for instance:

HP: 20
MP:4
Fire Resist: 2
etc…

But if it doesnt have anything greater than 0 I dont want any of that text to show.
I still want it to stay right under one another though so if it has different stats it still shows up with the same spacing ie: on another item maybe its this.

HP: 12
Fire Resist: 2
Poison Resist: 1

Then the solution would be using a dynamic vertical box. Feed those values into the vertical box dynamically using the blueprint. Dynamic means it can update/change the values in runtime.
But before that, you have to do a lot of branches of checks before you feed the value into the vertical box.

Hope it helps.

you might put the variables into an array and then use for each loop to check each value being more than 0.

If not more than zero, keep the UI element collapsed (or hidden if you dont want spacing to change). If more than 0, make the UI element visible and set the text to variables number value.

Heya, yeah I mean I get how this is done I have it sorta setup that way now I just didnt now how I could make it “Dynamic” I guess. So it would stack the same no matter what stats were populated great than 0.

You can keep it static, too. As you iterate through the text block to update, collapse the ones you’d set to 0. Crude pseudo-script:


Admittedly, this can be set up in many, many ways.

You could have each stat line represented by a user widget and only create the lines if a condition is met. Less performant but smaller memory footprint. Both costs are negligible if we’re talking about a handful of widgets at a time.

yeah simple way is to have the UI elements hardcoded in place.

But even if it is dynamic (you are adding children to a horizontal or vertical box at runtime), so long as the array is the same it will always be the same.

In other words, dont change elements in the array - just toggle visibility of elements in the array based on their values.

TBH, there are many ways to do it. For me, doing it dynamically will be easier and cleaner. It’s just the way I did it and the logic just gets executed once upon hovering, so not much of a tick to be used. You can minimize the use of referencing/variable as well if you are using dynamically.

You can work on static too or hardcoded, as long as it works.

So do I add all the Text blocks to the Tooltip widget or will it iterate them from the textblock widget? Sorry for all the question UMG is still a learning curve for me.

Any chance you have an Example of what you mean?

Fine, I’ll show you how to do it.
Take a look at the final result screenshot.

That white square is an image widget component and the “Fire: 10”/“HP: 20” is the tooltip.
So, let’s start.

  1. I have 2 blueprints widgets and a struct. Here’s what my content browser looks like.
    image

  2. This is what I have inside the structure.

  3. This is what I have inside the “TooltipText_Widget” blueprint. I just add the text and set the font size to 16. Make sure you check the box “Is Variable” for the text.

  4. Here’s what I have inside the TooltipText_Widget blueprint. Create a new text variable and check the box “Instance Editable” and “Expose on spawn” for the “TextStats” variable.

  5. Then the biggest part is the “Tooltip_Widget”. Here’s my designer tab for the “Tooltip_Widget”.
    Here’s my setup:
    - Border> padding:20 > color:black
    - VerticalBox > “Is Variable”: True > padding:10

  6. Inside the “Tooltip_Widget” blueprint. Create a new variable type “Stats Struc” and set it to an array type then name it “StrucRef”. So, your blueprint variables should look like this.

  7. This “StructRef” Variable is where you can feed your values/name/stats.

  8. Finally the core blueprint part of the logic. This is inside the “Tooltip_Widget” blueprint.

  9. Bonus, here’s what I have in my “main_widget” blueprint. Make sure the image “Is Variable” is True.

  10. It’s all dynamic. Because your vertical box is not constant. It can change in the runtime.

I really appreciate what you did here! thank you!

image
Cant thank you enough !