animating nodes not in the scene?

Godot Version

4.4 master branch

Question

I have some special effect sprites I wish to put on my characters when they are hit, and the way I want to do it is to use an animationplayer node to smothly adjust the alpha value of these sprites over a set time(just onr animation for all the effects). I don’t want to create an animationplayer for each character so I want to make one generic effect player and attach it the characters. problem is the standalone animationplayer can’t do anything, while the special effect sprite to play is decided at runtime. What is the best way to approach this?

current approach: I have a placeholder sprite in the same scene as the animationplayer, and just do my things on it. during runtime I swap in the actual special effect node, remove placeholder and give the special effect node the same name as placeholder. This feels like some hack though, I wonder if there’s cleaner way.

Can you share a short video of what you exactly want to achieve?
And scene structure + code snippets will also help to understand the situation better.

Side note - if you just want to change the alpha value of a sprite, I think the AnimationPlayer node might be an overkill, it’d say it’s easier to use Tween class for that from within the code. E.g. this piece of code will “animate” your sprite’s modulate’s alpha value linearly from 1.0 to 0.0 over 0.5 second.

var tween: Tween = create_tween()
tween.tween_method(func(value: float): sprite.modulate.a = value, 1.0, 0.0, 0.5)
1 Like

Hi, thanks for suggesting the tween class, it works for this simple use case, but let me try to explain my ideas with the 2d platformer demo.


the Enemy scene has an animation player that upon enemy destruction, rotate the sprite and adjust alpha. If I have 100 enemies that looks different but behave the same upon destruction, do I have to make 100 unique animation player for them? I hope I could make just one and attach it to enemy sprites to give it the ability to behave like this.

If the position relationship between the animation_player and the sprite remains unchanged, it can be applied directly. You can also just swap out the texture of the sprite.

1 Like