The best way to bind data to HUD?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By icqqq

I have a character with hp and a progress bar to display the hp.

Is there the best way to bind the hp data to progress bar value?

Currently I just update the progress bar value whenever my character hp is changed.
But I think it is not good as the character is coupled with the UI element. Therefore I want a way to bind data between the character and the progress bar.

Thank you.

Are you working in 2d or 3d ?
What is wrong with " the character is coupled with the UI element" ?

GameVisitor | 2018-06-17 08:14

in 3D, but what is the matter?
The problem is the character is not flexible and may be hard to manage if it coupled with UI

icqqq | 2018-06-17 15:29

:bust_in_silhouette: Reply From: Sprowk

You can do it with groups.

First you have to add node to a group: https://forum.godotengine.org/10513/how-to-add-nodes-to-a-group. Then you can get from tree array of nodes of that group.

Simple example:

var nodes_update = get_tree().get_nodes_in_group("character_hud")
for i in range(nodes_update.size()):
	nodes_update[i].your_function(data)