+2 votes

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.

in Engine by (248 points)

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

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

1 Answer

0 votes

You can do it with groups.

First you have to add node to a group: https://godotengine.org/qa/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()):
by (330 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.