• RuntimesUnity
  • AnimationState.Complete fires too late

I want to hide some sprites based on AnimationState.Complete for my animations. It would work fine, but there is some unpleasent delay here. I have tried to use End, but with same result. I think I have found out the reason, it is default mixing 0.2sec. If i add custom mix 0 for my two anims, it works fine. But in general I like soft autointerpolated transitions.

Is any way to hang a callback on Complete, that fires on Animation End if mix would be 0. But with real mix. Maybe something like AnimationState.StartMixNext or similar. Using event on last frame for each anim is pretty tedious repetative manual task.

  • Harald ответили на это сообщение.
    Related Discussions
    ...

    To address the delay issue with the AnimationState.Complete event due to the default mixing duration, you can use a combination of AnimationState.Update and custom event handling to achieve the desired behavior. Here’s a solution that allows you to maintain smooth transitions while ensuring your callback fires at the correct time:

    1. Set Up a Custom Event Listener: Create a custom event listener that checks if the animation is complete, considering the mix duration.

    2. Update Animation State: Ensure the animation state is updated correctly within your game loop to handle the timing accurately.

    Here’s an example of how you can implement this in your code:

    void Start() {
        skeletonAnimation.AnimationState.Complete += OnComplete;
        skeletonAnimation.AnimationState.Event += OnEvent;
    }
    
    void OnComplete(TrackEntry trackEntry) {
        if (!trackEntry.Loop && trackEntry.Next == null) {
            // Your logic for when the animation completes
            HideSprites();
        }
    }
    
    void OnEvent(TrackEntry trackEntry, Event e) {
        if (e.Data.Name == "end") {
            // Your logic for when the animation ends
            HideSprites();
        }
    }
    
    void Update() {
        skeletonAnimation.AnimationState.Update(Time.deltaTime);
    }
    
    void HideSprites() {
        // Logic to hide sprites
    }

    In this example:

    • OnComplete handles the completion of the animation.
    • OnEvent can be used to handle custom events, such as an "end" event you might define in your animation.
    • Update ensures the animation state is updated every frame.

    By using this approach, you can maintain smooth transitions with a mix duration while ensuring your callback fires at the correct time.

    Maltakreuz изменил(а) название на "AnimationState.Complete fires too late".

    Maltakreuz It would work fine, but there is some unpleasent delay here. I have tried to use End, but with same result. I think I have found out the reason, it is default mixing 0.2sec. If i add custom mix 0 for my two anims, it works fine.

    This sounds like you want a callback to happen at interrupt when mixing-out starts (0.2s before the end), not when it ends, as Nate suggested. Note that a mix duration of 0.2s makes animations overlap by this mix duration, not hold the last frame for 0.2s.