SpriteFrames.get_frame_texture() doesn't return the texture of the frame

Godot Version

4.2.2

Question

I’m trying to use SpriteFrames to implement an animated texture from a spritesheet.
Because it’s clearly made to contain sprite animations.

My animation looks like this :

Then why does sp.get_frame_texture("default", 2) return me this image ?
base spritesheet

It’s the original spritesheet that I imported to create the frames, but I expected the function to return only the “3” part.

I don’t think it’s expected behavior, but the documentation is too sparse on this point.

Yes thats weird. I also believe its supposed to return frame number 2.
Can you show your code so we can make sure its a bug and not a code issue?

I made a new project to have a minimal reproduction.

Code of the root :

extends Node3D

@onready var mesh_instance_3d: MeshInstance3D = $MeshInstance3D

@export var sprites: SpriteFrames

func _ready() -> void:
	var material = mesh_instance_3d.mesh.surface_get_material(0)
	material.albedo_texture = self.sprites.get_frame_texture("default", 2)

Then you might want to open a github issue.
Do you need a workaround while this is open?

Gladly !

(link to the opened issue : SpriteFrames.get_frame_texture() return the whole spritesheet instead of one frame texture · Issue #98320 · godotengine/godot · GitHub)

It seems that the get_frame_texture() returns an AtlasTexture, with the whole spritesheet, but also the right region.

Then using get_frame_texture().get_image() returns an Image exactly as we want it.

var texture: AtlasTexture = sprites.get_frame_texture("default", 2)
var new_texture: ImageTexture = ImageTexture.create_from_image(texture.get_image())
var material = self.get_surface_override_material(0)
material.albedo_texture = new_texture

As this is expensive, I will cache those ImageTexture for later loops.

1 Like