Load texture to Animated Texture's frame0/texture property from script

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

Hello trying to load a texture to a Texture text node → Animated Texture (selected for text) frame 0 texture property (frame0/ texture) from script.
I have a 150 frames of animation and if i have to load this one by one from inspector it will be hell. I think if i can load it with script then i can write a ’ for loop ’ for easy load. Can you help me?

:bust_in_silhouette: Reply From: njamster

Like this?

for i in range(150):
	# your texture's paths may differ!
	var texture_path = "res://texture_" + str(i) + ".png"
	$TextureRect.texture.set_frame_texture(i, load(texture_path))

First of all thank you very much.
I tried both loading images manually and by script.
To use script you have to set frame number manually
Script doesn’t do it by the way. Problem is when i use
Script in the end of loop animation stops like a quarter
Of a second. Do you have any idea why it happens.
Can it be because loading from script adds extra work on engine.

unholy182000 | 2020-09-22 19:22

Can it be because loading from script adds extra work on engine.

No. It’s called only once when the scene becomes ready. And shouldn’t be any different from setting the textures manually in the editor.

To use script you have to set frame number manually

Well, yes. You can do this from script as well though:

$TextureRect.texture.frames = 8

when i use script in the end of loop animation stops like a quarter of a second

I cannot reproduce this, works fine for me. If you upload a minimal example project somewhere and provide a link here, I can take a look.

njamster | 2020-09-25 12:40