Animation fading out inconsistently

Godot Version

4.5

Question

Hey there! Total noob here - but I managed to somewhat attach a fade-out to one of my AnimatedSprites by attaching an AnimationPlayer and modulating the opacity.

It’s meant to play once when an Area2D is clicked, then fade out. I thought I’d found a pretty solid solution, (code here:)

extends Sprite2D

@onready var panel = $Panel
@onready var animated_sprite = $AnimatedSprite2D2

func _on_area_2d_4_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) → void:
if event is InputEventMouseButton and event.pressed:
animated_sprite.play(“default”)
animated_sprite.visible = true

func _on_animated_sprite_2d_animation_finished() → void:
panel.visible = true

In the accompanying AnimationPlayer, I selected a runtime of 3 seconds, with full opacity at 1 and 0% opacity at 3. The original “default“ animation (consisting of 22 different frames) is meant to last 5 seconds or so, and it looks like the fade happens as intended.

But whenever i run the scene, the nature of the fade changes. Sometimes, it looks like the final frame of the animation lasts for way longer, while other times the default animation is already faded from the start. This is without me changing ANYTHING about the code at all, simply running the scene a few times back to back and going through the exact same motions.

I wouldn’t super mind the randomness if it weren’t so clear that i messed something up i don’t even fully understand. I would appreciate help.

Best,

Ari

Did you create a RESET animation?

Also, please format your code like this:

```gd
#Code here
```

So it looks like this:

#Code here
1 Like

Oh, thank you so much for explaining.

I was wondering about that formatting. Update for clarity:

gd

extends Sprite2D

@onready var panel = $Panel1
@onready var animated_sprite = $AnimatedSprite2D


func _on_area_2d_4_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
      if event is InputEventMouseButton and event.pressed:
          animated_sprite.play("default")
          animated_sprite.visible = true
          

func _on_animated_sprite_2d_animation_finished() -> void:
  panel.visible = true 

```

I checked out RESET animation but all i found so far were implementation suggestions for future updates? I’d really appreciate if you could explain how to do this

Thank you :folded_hands:

  1. Make sure your the Animation Tab is selected:
  2. Select the Node in you Scene Tree that you want to animate.
  3. Click the Key Icon in the Inspector next to the property you want to add a track for.
  4. The Please Confirm… dialog will appear.
  5. Make sure the Create RESET Track(s) option is checked.
  6. Click the Create button.
  7. A RESET Animation will be created.

Every time you save the Scene the Animation Player is in, or create it in the game, it will load the RESET track. This will reset everything back to “normal”. You can edit each property in the RESET track to change values.

You should always make a RESET track to avoid inconsistencies with your Animation Player.

Thank you so much for taking the time to explain so thoroughly, and even with screenshots. I’m marking this as completed because while whatever was wrong seems to have been ultimately unrelated, it’s a great hint I didn’t know about and probably good to come back to if I run into trouble here.

Thanks again for the help, I really appreciate it!

1 Like