godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.49k stars 21.07k forks source link

Weird behavior when deleting SpriteFrames from AnimatedSprite2D #75432

Open SvenVanSnooze opened 1 year ago

SvenVanSnooze commented 1 year ago

Godot version

4.0.1

System information

Windows 11

Issue description

When deleting SpriteFrames from AnimatedSprite2D after you manually deleted all corresponding animations it still tries to load Animations and outputs errors to the console. It took me some time to find the root of this problem and i think when you delete SpriteFrames from AnimatedSprite2D Godot should automatically clear all animations. Godot behaves correctly when there is one animation left minimum. But behaves weird when there are no animations left.

Steps to reproduce

Really easy:

Debugger: E 0:00:00:0324 set_animation: There is no animation with name ''. <C++ Error> Method/function failed. <C++ Source> scene/2d/animated_sprite_2d.cpp:528 @ set_animation()

Minimal reproduction project

N/A

Rouli-M commented 1 year ago

+1

Any way to fix this issue? Reloading the project won't remove it, it my logs are being spammed.

edit: At least I think it's the same issue, I've deleted my SpriteFrames at some point and the logs keeps spamming something similar:

 scene/resources/animation.cpp:1414 - Index p_track = -1 is out of bounds (tracks.size() = 5).
  scene/resources/animation.cpp:1768 - Index p_track = -1 is out of bounds (tracks.size() = 5).
  Animation '<null>' doesn't exist.
SvenVanSnooze commented 1 year ago

+1

Any way to fix this issue? Reloading the project won't remove it, it my log are being spammed.

edit: At least I think it's the same issue, I've deleted my SpriteFrames at some point and the logs keeps spamming something similar:

 scene/resources/animation.cpp:1414 - Index p_track = -1 is out of bounds (tracks.size() = 5).
  scene/resources/animation.cpp:1768 - Index p_track = -1 is out of bounds (tracks.size() = 5).
  Animation '<null>' doesn't exist.

In my case i fixed it by readding SpriteFrames to my AnimatedSprite2D. It automatically creates a default animation again. Now you can safely delete SpriteFrames.

kdiduk commented 1 year ago

Looking at the code of AnimatedSprite2D, once the animation is set using set_animation(), there is no way to "unset" it. After we delete the last animation in the SpriteFrames attached to AnimatedSprite2D, the editor calls set_animation() with an empty string, which leads to an error message.

On the other hand, there are other problems around that. For example, in the inspector of AnimatedSprite2D when we reset to defaults animation property, it's always reset to "default" even if there is no animation with the name "default" in the SpriteFrames. Even if there are no animations in SpriteFrames, we can still reset the animation to "default".

A simplest solution would be to add a special method to AnimatedSprite2D like reset_animation() or clear_animation() to reset it without showing that error. And that method should be called when the last animation in the SpriteFrames is deleted.