godot icon indicating copy to clipboard operation
godot copied to clipboard

AnimatedSprite2D: Empty Animation name error on ready/instantiation propagates to inherited scenes

Open hsandt opened this issue 1 year ago • 1 comments

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

  1. In the MWE I prepared many variants of nodes with AnimatedSprite2D (and even AnimationLibrary but it doesn't seem to matter)

  2. 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

  3. 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

  4. Note: don't worry about the Animation Player, I left it here because it was easier but it shouldn't affect the result

  5. 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.

  6. In any scene with the error, select AnimatedSprite2D and observe the Sprite Frames and Animation with reset button on empty field

image

  1. Reassign Sprite Frames to sprite_frames_aoe_ice_spikes.tres temporarily. Default animation is now Active.
  2. 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)
  3. If you run the scene you just edited or a child one, the error is gone...
  4. But in practice you want to get rid of Sprite Frames on "abstract" base scenes, so clear the Sprite Frames again
  5. 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()

  1. 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).
  2. If you check git diff, you'll see that Sprite Frames is now set but animation field is the empty string animation = &""
  3. Run scene and see the original error with an empty string again, as expected.
  4. We're now back to step 1!
  5. 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

hsandt avatar Feb 08 '24 20:02 hsandt

I found a workaround for a quick cleanup without recreating nodes nor touching the serialized text files: instead of assigning a SpriteFrames, create a new SpriteFrames, then clear it again.

This will clean up the Animation empty string value.

image

It seems that temporarily creating a default animation in the SpriteFrames just to get a proper reset value before clearing SpriteFrames also works (as suggested in some Godot 3 issue https://github.com/godotengine/godot/issues/40263), but this is even faster!

hsandt avatar Feb 08 '24 20:02 hsandt