Repository: godot
Issue: AnimatedSprite2D: Empty Animation name error on ready/instantiation propagates to inherited scenes
Labels: bug,topic:animation

### Tested versions

- Reproducible in v4.2.1.stable.official [b09f793f5]

### System information

Godot v4.2.1.stable - Ubuntu 22.04.3 LTS 22.04 - X11 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 860M (nvidia; 535.154.05) - Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz (8 Threads)

### Issue description

This is a reboot of https://github.com/godotengine/godot/issues/28658

It was said to be fixed in 3.6, so it may be a Godot 4 regression.

However, my issue here goes farther: not only does an AnimatedSprite2D never get a correct default animation once the SpriteFrames has been deleted (empty string, even when default animation exists) causing an error on start:

> E 0:00:00:0472   set_animation: There is no animation with name ''.
  <C++ Error>    Method/function failed.
  <C++ Source>   scene/2d/animated_sprite_2d.cpp:528 @ set_animation()

but **any inherited scene will also inherit the bug, even if they themselves define a proper SpriteFrames and default animation.**

Since it's common that I create a Base scene from which I create Inherited scenes for various objects of the same type, this messes up all these objects.

This happens on ready if object is in scene, or during instantiation if object is spawned from a PackedScene.

I managed to use the trick to reassign a SpriteFrames resource, click the reset button to clean up the default animation and then remove the SpriteFrames resource once, but I could never reproduce it. So I don't have a way to fix my existing corrupted base object except changing the text file or recreating a new AnimatedSprite2D node from scratch (which will break things in my inherited scenes).

### Steps to reproduce

0. In the MWE I prepared many variants of nodes with AnimatedSprite2D (and even AnimationLibrary but it doesn't seem to matter)
1. Open Scences/demo_**inherited**.tscn (alternatively AOE_IceSpike_**Inherited**.tscn directly) and Run this scene (F6) => **see the error even though the inherited scene is setup correctly**
2. Open Scences/demo_isolated.tscn which contains exactly the same object, but I cut inheritance relationship with AOEBase.tscn (alternatively, open AOE_IceSpike_Isolated.tscn directly), and Run this scene (F6) => there is no error

3. Note: don't worry about the Animation Player, I left it here because it was easier but it shouldn't affect the result

4. You can also try variations of AOE_Base with and without animation library, such as AOEBase_WithoutAnimationPlayer.tscn and AOEBase_WithoutAnimationPlayer_Child.tscn. The result is the same, as AnimationLibrary doesn't affect it.
5. In any scene with the error, select AnimatedSprite2D and observe the Sprite Frames <empty> and Animation with reset button on empty field

![image](https://github.com/godotengine/godot/assets/1067772/ea0f865a-b092-4a07-ae09-add46a8e887f)

6. Reassign Sprite Frames to sprite_frames_aoe_ice_spikes.tres temporarily. Default animation is now Active.
7. Click the reset button to reset to default. As long as default animation exists, it will do it (if default animation doesn't exist, it may look like it resets to default but Output error "Animation 'default' doesn't exist.". Sometimes it will properly "bounce" the property back to the previous value in the inspector, but not always... but that's another issue - we assume default exists here just to avoid stacking even more errors)
8. If you run the scene you just edited or a child one, the error is gone...
9. But in practice you want to get rid of Sprite Frames on "abstract" base scenes, so clear the Sprite Frames again
10. Run the scene

You get the same error except with "Active"

> E 0:00:00:0474   set_animation: There is no animation with name 'Active'.
  <C++ Error>    Method/function failed.
  <C++ Source>   scene/2d/animated_sprite_2d.cpp:528 @ set_animation()

11. Click on the reset button near Animation to reset Animation to "default" => this time, you get the error "There is no animation with name 'default'." (it looks like "Animation 'default' doesn't exist." but it's a bit different - and it will happen every time, since we cleared Sprite Frames so the default animation can never exist - but the error message is misleading on the nature of the error).
12. If you check git diff, you'll see that Sprite Frames is now set but animation field is the empty string `animation = &""`
13. Run scene and see the original error with an empty string again, as expected.
14. We're now back to step 1!
15. You can also try to clear Sprite Frames and then Animation on the child scene AOE_IceSpike_Inherited.tscn: you'll see an error "There is no animation with name ''. But I'm more worried about having an error when the child scene is fully set because of an invisible link to some base scene.

### Minimal reproduction project (MRP)

[v4.2.1 - There is no animation in name empty - Godot 4 Platformer 2024-02-08 stripped.zip](https://github.com/godotengine/godot/files/14214378/v4.2.1.-.There.is.no.animation.in.name.empty.-.Godot.4.Platformer.2024-02-08.stripped.zip)