Skip to content

Instantly share code, notes, and snippets.

@andrew-wilkes
Last active November 16, 2020 12:37
Show Gist options
  • Select an option

  • Save andrew-wilkes/2de688ab97d4c44f1a4ebc92c49aa2ff to your computer and use it in GitHub Desktop.

Select an option

Save andrew-wilkes/2de688ab97d4c44f1a4ebc92c49aa2ff to your computer and use it in GitHub Desktop.
Implementing a Tool script in Godot Engine to update a Label text in an Instantiated scene
tool
extends Control
# Set a default value and call the setter and getter functions as needed
# But this txt value IS NOT SAVED in an instantiated scene
export var txt = "Y0" setget set_text, get_text
# But this text value IS SAVED in an instantiated scene
# And it is displayed in the Inspector panel (we don't want that to happen)
export var text: String
func _ready():
$Label.text = text
# This setter function seems to be called by the Editor before the Label is in the scene producing error messages
# if we don't check that the Label exists
# And I am not sure of the significance of the property_list_changed_notify function call
func set_text(t):
if Engine.editor_hint and has_node("Label"):
$Label.text = t
text = t
property_list_changed_notify()
func get_text():
return text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment