About new animation system with triggers

Hi,
just had a look into the new animation state system, which looks quite a lot like the unity version.
Fine. But I am already lost with triggers. Just having an idle state should start transitions by keyboard. since its a trigger it should just start but then… it is not playing the complete animation.

Desired behavior: Set the trigger, animation plays and on end it goes back to the last state.
Current behavior: trigger is set, I see a one frame flash and it is back on the last state.

What is the correct condition to go back to a parent state after using a trigger?

Or do I need to use booleans? But then, what is a trigger for?

code segment:

AnimStateController.prototype.keyDown = function (e) {
    if ((e.key === pc.KEY_P) && (this.entity.anim.baseLayer.activeState !== 'punch')) {
        console.log("punch");
        this.entity.anim.setTrigger('punch');
    }
};


AnimStateController.prototype.keyDown = function (e) {
    if ((e.key === pc.KEY_K) && (this.entity.anim.baseLayer.activeState !== 'kick')) {
         console.log("kick");
        this.entity.anim.setTrigger("kick");
    }
};

If that’s the case, there’s a transition that has no conditions or the conditions have been met that transitions to your ‘last’ state.

If you have a simple reproducible, it would be great to share the project.

you should have an invitation for a simple demo

(as I quickly assembled this and cannot see the result, I have no idea what animations would be played on keypress)

I’m not sure, but can’t you solve this problem with setting the Exit Time of the transition back to 1?

To further explain this:

It starts in fightidle. You set the trigger punch so the transition conditions from fightidle to punch are all met and the graph is in state punch.

Now that it is in state punch, the transition conditions from punch to fightidle are all met because there are no conditions and therefore the graph transitions to fightidle.

If you want to play the full animation of punch, as Albertos said you need to set the exit time of the transition from fightidle to punch to 1.

Read more here about exit time: https://developer.playcanvas.com/en/user-manual/animation/anim-state-graph-assets/#transitions

This basically allows you to prevent the state that it is transitioning to, transitioning out until the exit time (normalised time).