Setget exported string variable failing, and always returning to the default value. Why?

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

I am currently trying to automate an update to my child label to be runned in the editor, however it always returns to it’s default value after I click on another node, I’ma show as it’s easier than explaining:

The node structure of the scene is

World node:
    Node2D -> Box
        Label
    Node2D -> Box1
        Label

BOX, Node2D code:

tool
extends Node2D
    
export(String) var ItemID = "NOONE" setget UpdateMyLabel

func _ready():
	pass 

func UpdateMyLabel(newName):
	if Engine.editor_hint:
		$Label.set_text(newName)

I duplicate the Box a fewer times, select the first and type in the exported var, it works, the label get’s renamed, however when I select another box, the ItemID on the previous node get’s reset to “NOONE”, but the label doesn’t update, and if I print it really changed to the default value: NOONE. Why is that?

There’s not anything more running in the background, I recreated this with a clean scene.

:bust_in_silhouette: Reply From: Mike Trevor

You’re gonna have to update ItemID in the set function UpdateMyLabel, it’s not gonna update itself. Add ItemID = newName on the last line of the set function.

func UpdateMyLabel(newName):
    if Engine.editor_hint:
        $Label.set_text(newName)
    ItemID = newName