godotengine / godotengine/godot-docs

AnimatedSprite2D.play() behavior change between Godot 3 and Godot 4 should be documented

Open
#8,372 12 comments 1 reaction 0 assignees View on GitHub
area:manual enhancement
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

### Godot version

4.1.2.stable.flathub [399c9dc39]

### System information

Godot v4.1.2.stable (399c9dc39) - Freedesktop SDK 23.08 (Flatpak runtime) - Wayland - Vulkan (Compatibility) - Mesa Intel(R) Xe Graphics (TGL GT2) () - 11th Gen Intel(R) Core(TM) i5-11320H @ 3.20GHz (8 Threads)

### Issue description

I find a behavior difference between Godot 3 and Godot 4, that when an AnimatedSprite2D node plays a non-looping animation, it actually becomes looping when .play() API is called within _process() or _physics_process().

```GDScript
func _process(delta) -> void: # Same behavior on _physics_process() as well
$AnimatedSprite.play("collected") # Animation "collected" is marked as non-looping in Editor
```

This behavior can be workarounded by moving the .play() call out from _process(), but put it to _ready(). Example is in [demo_animated_sprite_2d_non_loop_good.tscn](https://github.com/fuzhouch/godot-3to4-comparison/blob/main/godot4/demo_animated_sprite_2d_non_loop_good.tscn).

However, the code above is different with Godot 3. When running the code above in Godot 3, the sprite animation plays once, and stops at last frame. There's no looping happening, matching the settings in SpriteFrames.

The same behavior is observed on both Linux and macOS.

### Additional Context
The issue was discovered from a migration of an action game project from Godot 3.5.3 to Godot 4.1.2. In original version, a lot of my code rely on behavior above, to implement a pattern of separating status change to different signal handlers (simplified code sample is shown below). Due to the change in Godot 4, a lot of code needs to be changed, because many non-looping actions (e.g. throwing fireballs) now play in a repeated manner.

I tried to find from Godot engine Q&A and Stackoverflow but not lucky enough to see a thread talking about this.

I'm not blocked because the workaround is available, but I would like to understand why the behavior between Godot 3 and 4 is inconsistent. Is it an intended behavior change in Godot 4?

```GDScript
var action_status = "animation_name"
func _physics_process(delta):
$AnimatedSprite.play(action_status)

func _signal_handler_being_hit():
action_status = "hit"

func _signal_handler_being_bomb_blown_off():
action_status = "fly_hight"
```

### Steps to reproduce

1. Checkout project https://github.com/fuzhouch/godot-3to4-comparison/ to local, say ./godot-3to4-comparison.
2. Launch Godot 4.1.2. Open godot 4 project, ./godot-3to4-comparison/godot4/project.godot
3. From Godot 4 editor, Launch scene, [demo_animation_sprite_2d_non_loop_bad.tscn](https://github.com/fuzhouch/godot-3to4-comparison/blob/main/godot4/demo_animation_sprite_2d_non_loop_bad.tscn)

NOTE: The project is kinds of as minimal as possible. It contains multiple scenes, while each of which are presenting a single bug. Every scene is self-contained, and do not depends on each other.

We can see the gold coin keep flashing on launch.

As a comparison, please

1. Launch Godot 3.5.3, then open Godot 3 project, ./godot-3to4-comparison/godot3/project.godot
2. From Godot 3 editor, Launch scene, [Demo_AnimatedSprite2D_NonLoop.tscn](https://github.com/fuzhouch/godot-3to4-comparison/blob/main/godot3/Demo_AnimatedSprite2D_NonLoop.tscn)

The gold coin flashes only once and stop at last frame, a mini-coin.

### Minimal reproduction project

Project repository: https://github.com/fuzhouch/godot-3to4-comparison/
Godot 4 project path (for reproducing issue): godot4/
Godot 3 project path (for behavior comparison): godot3/

* The scene we use to reproduce the bug: [demo_animation_sprite_2d_non_loop_bad.tscn](https://github.com/fuzhouch/godot-3to4-comparison/blob/main/godot4/demo_animation_sprite_2d_non_loop_bad.tscn)
* The scene that shows workaround: [demo_animated_sprite_2d_non_loop_good.tscn](https://github.com/fuzhouch/godot-3to4-comparison/blob/main/godot4/demo_animated_sprite_2d_non_loop_good.tscn)
* The scene (under project godot3, requires Godot 3.5.3) for behavior comparison: [Demo_AnimatedSprite2D_NonLoop.tscn](https://github.com/fuzhouch/godot-3to4-comparison/blob/main/godot3/Demo_AnimatedSprite2D_NonLoop.tscn)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.