Can't get text animations working via GDScript

Godot Version

Godot v4.2.1-stable

Question

Set animation wouldn’t play

func _ready():
	var test = "TestText Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
	text = test
	var visibleRatio = "RichTextLabel:visible_ratio"
	var animation = Animation.new()
	animation.set_length(1)
	var track_index = animation.add_track(Animation.TYPE_VALUE)
	animation.track_set_path(track_index, visibleRatio)
	animation.track_insert_key(track_index, 0, 0)
	animation.track_insert_key(track_index, 1, 1)

	var lib = AnimationLibrary.new()
	lib.add_animation("start",animation)
	
	var pAnim = AnimationPlayer.new()
	pAnim.add_animation_library("textanims",lib)
	pAnim.play("textanims/start")

I’m new to Godot.
I’m trying to get the text to appear smoothly but it doesn’t show up at all. I’ve looked all over for tutorial and such but everything i found is outdated.

Give this a try:

var tween := create_tween()
tween.tween_property($RichTextLabel, "visible_ratio", 1.0, 1.0)

gives 3 errors:


E 0:00:00:0479   Start.gd:20 @ _ready(): Node not found: "RichTextLabel" (relative to "/root/Node2D/ColorRect/MarginContainer/VBoxContainer/RichTextLabel").
  <C++ Error>    Method/function failed. Returning: nullptr
  <C++ Source>   scene/main/node.cpp:1638 @ get_node()
  <Stack Trace>  Start.gd:20 @ _ready()

E 0:00:00:0479   Start.gd:20 @ _ready(): Parameter "p_target" is null.
  <C++ Source>   scene/animation/tween.cpp:103 @ tween_property()
  <Stack Trace>  Start.gd:20 @ _ready()

E 0:00:00:0483   step: Tween (bound to /root/Node2D/ColorRect/MarginContainer/VBoxContainer/RichTextLabel): started with no Tweeners.
  <C++ Error>    Method/function failed. Returning: false
  <C++ Source>   scene/animation/tween.cpp:319 @ step()

I’ve worked around the problem like this.
I don’t know if this is the best solution(probably not).

func _ready():
	text = "TestText Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
	
	var charPsec = 1.0
	
	var lent = (get_total_character_count()*1.0) / charPsec
	
	var animation = Animation.new()
	animation.set_length(lent)
	animation.add_track(Animation.TYPE_VALUE)
	animation.track_set_path(0, "%RichTextLabel:visible_ratio")
	animation.track_insert_key(0, 0, 0)
	for x in range(get_total_character_count()):
		animation.track_insert_key(0, (1 / charPsec)*x , x / (get_total_character_count()*1.0))
		print((1 / charPsec)*x ," ", x / (get_total_character_count()*1.0))
	
	
	var lib = AnimationLibrary.new()
	lib.add_animation("start",animation)
	
	$AnimationPlayer.add_animation_library("textanims",lib)
	$AnimationPlayer.play("textanims/start")

I can set the speed by modifying charPsec .
Currently it’s 1 character/second.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.