Sprite does not hide even when the conditions are satisfied.

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

Hello I have a life system and I have a life UI where it has 3 hearts. I want the 3 hearts to disappear one by one when the player is hurt but it doesnt disappear/hide. Here’s my code:

    extends Control


# Declare member variables here. Examples:
# var a = 2
# var b = "text"


# Called when the node enters the scene tree for the first time.
func _ready():
	if Global.player_life == 3:
		get_node("HBoxContainer/LifeIcon").show()
		get_node("HBoxContainer/LifeIcon2").show()
		get_node("HBoxContainer/LifeIcon3").show()
	
	if Global.player_life == 2:
		get_node("HBoxContainer/LifeIcon").show()
		get_node("HBoxContainer/LifeIcon2").show()
		get_node("HBoxContainer/LifeIcon3").hide()
	
	if Global.player_life == 1:
		get_node("HBoxContainer/LifeIcon").show()
		get_node("HBoxContainer/LifeIcon2").hide()
		get_node("HBoxContainer/LifeIcon3").hide()
		
	if Global.player_life == 0:
		get_node("HBoxContainer/LifeIcon").hide()
		get_node("HBoxContainer/LifeIcon2").hide()
		get_node("HBoxContainer/LifeIcon3").hide()
:bust_in_silhouette: Reply From: Zylann

Your code is inside the _ready function. As the comment says, this function is only called once after the node entered the scene tree. It will not be called again so when player_life changes it does not update.
You should probably move this code in another function, and call that function when player_life changes, either manually when you set player_life, or using a signal maybe. Or you could move this logic in _process.