godotengine / godotengine/godot
Setting AnimatedSprite2D.autoplay string in `_ready()` works, but issues a contradictory warning
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible in v4.3.dev3.official [36e943b6b]
### System information
Windows 10
### Issue description
When using `AnimatedSprite2D`, setting the autoload string to `""` in the `_ready` function works to prevent autoloading.
However, in the debugger I get warnings like (this is a built-in script):
```
W 0:00:02:0689 movie_loop.tscn::GDScript_d5yvq:15 @ _ready(): Setting autoplay after the node has been added to the scene has no effect.
scene/2d/animated_sprite_2d.cpp:449 @ set_autoplay()
movie_loop.tscn::GDScript_d5yvq:15 @ _ready()
```
I do not know the intended behavior / intended timing of when autoplay is supposed to start, but I've been using the _ready function as a opportunity to dynamically affect autoplaying on these AnimatedSprite2D nodes so I'd like to know sooner than later if that capability will be 'fixed' in a future version. :)
### Steps to reproduce
1. Add an AnimatedSprite2D with an animation set to autoload.
2. Attach a script like this one:
```gdscript
extends AnimatedSprite2D
@export var wait_to_start := 5.0
# The purpose of this snippet is to delay when the node starts autoplaying by wait_to_start seconds.
func _ready():
if wait_to_start != 0 and autoplay != "":
get_tree().create_timer(wait_to_start).timeout.connect(play.bind(autoplay))
autoplay = ""
```
3. Start the scene; the autoplay is delayed.
4. View the debugger; the debug warning is present.
### Minimal reproduction project (MRP)
[autoplay_warning_bug.zip](https://github.com/godotengine/godot/files/14271971/autoplay_warning_bug.zip)
Contributor guide
Research direction
Start with the minimal reproduction project and inspect scene/2d/animated_sprite_2d.cpp at set_autoplay(), then reproduce the warning from the script’s _ready() call. Done means the intended autoplay timing is established and the observed playback behavior and debugger warning are consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100