0 votes

Hi,

I have two animations for "Sprite" :
- DamageAnimation
- DeathAnimation
They worked like that :
- time : 0 | Set shader and default shaders params
- time : ]0;1[ | Change shader params
- time : 1 | Remove shader & call method

Both are created in code and when I play one of them it works perfectly.
The problem occurred when I play one after another.

The first one is executed, I can call this animation one or more times. When I play the second one, shader and related values aren't set BUT method are called. No error are fired from Godot and when I try to debug, tracks are set and filled with initial values (no problem) but tracks for shaders doesn't work. I tried with others values (like Modulate) and it works only for method and modulate.

Here is my code :

public bool PlayAnimation(EntityAnimation entityAnimation)
{
    if (_effectAnimationPlayer.HasAnimation(entityAnimation.ToString()))
    {
        _effectAnimationPlayer.Stop();
        _effectAnimationPlayer.Play(entityAnimation.ToString());
        return true;
    }

    return false;
}

protected virtual void CreateDamageAnimation()
{
    var material = new ShaderMaterial() { Shader = GD.Load<Shader>("res://Resources/Shaders/SpriteColor.tres") };
    material.SetShaderParam("color", new Color().FromRGBA(255, 0, 0, 1));
    var animation = new Animation();
    animation.Length = 0.5f;
    animation.Loop = false;
    animation.Step = 0.1f;
    animation.AddTrack(Animation.TrackType.Value, 0);
    animation.AddTrack(Animation.TrackType.Value, 1);
    animation.AddTrack(Animation.TrackType.Method, 2);
    animation.TrackSetPath(0, GetPathTo(_sprite) + ":material");
    animation.TrackSetPath(1, GetPathTo(_sprite) + ":material:shader_param/active");
    animation.TrackSetPath(2, GetPathTo(this));
    animation.TrackInsertKey(0, 0f, material);
    animation.TrackInsertKey(0, animation.Length, null);

    for (float i = 0; i < animation.Length; i += animation.Step)
    {
        animation.TrackInsertKey(1, i, i % (animation.Step * 2) == 0);
    }

    animation.TrackInsertKey(1, animation.Length, false);
    animation.TrackInsertKey(2, 0f, new Dictionary<string, object>()
    {
        { "method", nameof(OnDamageAnimationStarted) }, { "args", new object[] {} }
    });
    animation.TrackInsertKey(2, animation.Length, new Dictionary<string, object>()
    {
        { "method", nameof(OnDamageAnimationEnd) }, { "args", new object[] {} }
    });
    _effectAnimationPlayer.AddAnimation(EntityAnimation.EntityDamage.ToString(), animation);
}

Thanks for your help

Godot version v3.4.2 Mono
in Engine by (21 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.