Topic was automatically imported from the old Question2Answer platform.
Asked By
goshot
I thought this would work:
tool
extends Label
func set_text(t):
print(t)
But whenever selecting this node in the scene tree and typing text into the Text box underneath Label in the inspector, this function does not get called. “Set text” appears in the Output panel. How do we get a function called whenever label text is modified in the Inspector?
I don’t think it’s possible to react to text being changed. What do you need this for?
You could maybe workaround this by listening for label redraws:
var previous_text = ""
func _draw():
if previous_text != text:
print("Text changed: ", text)
If you want to trigger something exactly when the text changes, you’ll have to do it differently with a custom property or function, instead of relying directly on text.
See the answer I posted - _set gets called for text like for other properties.
Your point is valid that if something calls set_text on the extended Label node before it is in the scene tree, code that depends on being in the scene tree will fail. That could probably be protected with an is_inside_tree check. My code works with resources, so does not have this issue.