#Label text wont set after first run

7 messages · Page 1 of 1 (latest)

tropic pike
#

I have below unique case.

var current_weapon: Node3D = null:
    set(value):
        current_weapon = value
        if current_weapon != null:
            display_weapon_name(current_weapon.name)

func _ready() -> void:
    # Set the machete as the current weapon
    current_weapon = $Weapons/Machete
    current_weapon.show()

func display_weapon_name(display_name: StringName) -> void:
    print_debug(display_name)
    weaponName.text = "Weapon: " + display_name

[Issue]: above code runs fine and but displays label only when run from _ready. if I run this on pressing keys, it runs even display print message, but does not display anything in Label. Infact it clears Label text.

spice scarab
#

You need to update it in process function

#

Once updated in ready function.

tropic pike
#

i didnt understand how do I update weaponName in process ?

spice scarab
#

In process function

#

Call the display weapon name function

night kelp
#

Or if you don't need to update the weapon every frame, then updating it in _unhandled_input() would work too. If it's supposed to update when you drop in an item, then it would be worth looking at a signal that triggers assigning the current_weapon, but to test it and keep it simple, I'd see if it works in unhandled_input() first, and then check for pressing a certain button like ui_accept or something.