How does GetHealthPercent() actually get called?

Hello, I’ve got everything working for this lecture, but I feel like I’m missing something in the explanation.

I’ve set up the function in the HUD that casts to the ShooterCharacter Pawn and calls GetHealthPercent(). However, I don’t understand what is telling the HUD function when it should run. It seems to get called magically when the player gets shot.

I’ve played around a bit with setting CurrentHealth and MaxHealth on a key press during the game, and the ShooterCharacter’s GetHealthPercent() function seems to get called when EITHER CurrentHealth or MaxHealth changes, but functions don’t normally listen in for changes to variables they reference like that as far as I know, so what’s going on? The whole thing feels weirdly back to front.

1 Like

I don’t think you tested this well enough. It is definitely called every tick so you shouldn’t use property bindings for anything anymore complex than what is done in the course.

You may want to switch to an event based system but I’d only worry about that if it’s shown to be an issue. “Premature optimisation is the root of all evil” and that.

1 Like

Ahh, I didn’t realise that this was called every tick. I might have missed something, but I don’t know if this was explained and I don’t think it’s obvious.

We set up the binding of the value to a function in the UserWidget designer, and then filled in what that function does in the graph area, but we never hooked that function up to a tick node. In the UserWidget graph area, there’s an “Event Graph” tab that has a tick node with an output pin there, which we don’t use, and that also led me to think “…well, it doesn’t look like we’re using tick here…”

Is the important point here that any bindings that are made in the Widget are automatically called on tick?

Also, are bindings used extensively elsewhere in Unreal Engine, outside of doing things like this in Widgets?

It’s specifically for UMG

Property Binding | Unreal Engine Documentation

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms