Godot Version
Godot4.6
Question
am working on a 2D project in Godot 4 where I have a weapon XP system that controls a UI bar display.
What I am trying to do
I have a Player script that accumulates XP:
var xp_count: int = 0
func collect_xp(amount: int):
xp_count += amount
GameHUD.update_weapon_ui(xp_count)
The UI is handled by an Autoload singleton called GameHUD.
In the HUD, I display XP progress using 15 bar sprites:
@onready var weapon_bars := [
$weapon_level_bar/Panel/TextureRect,
...
]
And I update them like this:
func update_weapon_ui(weapon_xp: int):
var local_xp = weapon_xp % 15
if local_xp == 0 and weapon_xp != 0:
local_xp = 15
for i in range(weapon_bars.size()):
weapon_bars[i].visible = i < local_xp
The problem
The function is definitely being called correctly.
I confirmed this with debug prints:
-
weapon_xpvalues are correct and increasing -
local_xpis calculated correctly -
The loop runs and prints correct
true/falsevalues for each bar
However:
The UI does NOT visually update in-game.
The print() output shows correct visibility states like:
weapon_xp =3
local_xp =3
0 true
1 true
2 true
3 true
4 false
But the actual bars on screen do not change accordingly. When calling update_weapon_ui(5) from _ready(), UI displays correctly. When calling the same function later from Player script, logic runs but UI does not visually update. Any advice would be appreciated. Thank you in advance.