Simple Editor/Script Question - How To Change The Text Of RichTextLabel In GDScript Code?

Godot Version

v4.6.2.stable.official [71f334935] - Linux

Question

We have a RichTextLabel on the IDE editor.
We wish to change the text of the RichTextLabel.
We have below GDScript attached to the RichTextLabel.

Shows error when running though?
Invalid assignment of property or key ‘text’ with value of type ‘String’ on a base object of type ‘null instance’.

Any ideas about how to fix the above?
New to the IDE editor way of doing things.

SS

extends RichTextLabel


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	$RichTextLabel.text = "Hello, Godot 4!"
	
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass

You are already writing this code inside a RichTextLabel, but you are trying to reference another RichTextLabel. This isn’t required
You can simply do:
text = "Hello, Godot 4!"
You don’t need to reference another RichTextLabel.

That worked, thank you

1 Like