The problem with the sprite sheet animation (set_frame_coords: Index p_coord.y = 6 is out of bounds (vframes = 5))

I have a character who has two states: run and idle. I also have 2 sprite Sheets, where one has sprites for run animation (consists of 12 sprites), and the other for idle animation (consists of 5 sprites). To switch between these animations, I change the texture in Sprite2D of the character from one to another and change the value of h_frame from 5 to 12 and vice versa. Then an animation is launched on Animation Player, which changes frame_coords.x so that the animation works.
When the game starts, the idle animation works correctly, however, when I switch to the run state, the animation breaks and an error appears in the console

set_frame_coords: Index p_coord.y = 6 is out of bounds (vframes = 5)

I suspect this is because the idle sprite sheet has fewer frames than the run. I have already checked this, if I do not change the value of h_frame, then the animations are played and the error does not appear, however, in this case the animation does not look as intended.
Any solutions?

Are you changing the Texture in code, or are you doing it inside the animation itself? You should do it in the animation itself to avoid sync. issues.

You might also have a look at the RESET animation that is created automatically. That might refer to frames that aren’t there. That caught me out several times.

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