[SOLVED] Questions about state graph

Hello

I wanted to create a new topic because the previous one may have became complicated with a lot of questions.

I got 2 questions about the anim state graph that I could not solve.

  1. Is it possible to use exit time in transitions when you use the ANY state in the state graph? When I link from the ANY state I cannot get the exit time to work between individual transitions. See the below images of what I mean, I want to use the ANY state because otherwise i need to link lots of arrows between states to and from each other.

  1. How does interruption source work? I could not find much detail about that in the materials. Does that mean I can cancel a current animation and play another? so if i shoot i can cancel the currently playing reload animation? If so how could I get this to work?

Thanks

1 Like

@Elliott

1 Like
  1. What do you mean by ‘not working’? Would you be able to provide an example project to see the state graph setup?
1 Like

Have you set up a condition on the ANY > Idle transition which can be used to control when the graph transitions back to Idle? Otherwise it’ll always be available, keeping it in the Idle state.

With regards to interruption sources: By default transitions cannot be interrupted (i.e once the graph enters into a transition, that transition will fully complete before the graph can transition again). If you set the interruption source of a transition, you’re telling the graph which other transitions can interrupt the current one.

For instance if you have a graph with Idle > Walk > Run and an interruption source of none on all of your transitions, you’ll need to wait for the transition from Idle > Walk to complete before you can transition from Walk > Run. However if you set the interruption source of the Idle > Walk transition to next, you’ll be able to activate a transition from Walk > Run while the Idle > Walk transition is currently playing.

2 Likes

What I tried was 3 things:

  1. Making 2 transitions from ANY > Idle
    transition 1: movement speed <= 0
    transition 2: reload = false (exit time = 1)

When doing this the reload animation does not play properly.

  1. Making 1 transition from ANY > Idle where I would have 2 conditions and exit time = 1
    condition 1: movement speed <= 0
    condition 2: reload = false

When doing this the since exit time is = 1 for both conditions the walk continues playing after standing still but the reload animation works fine.

  1. Adding 2 separate transitions from the reload state to the walk and idle (as it is currently in the test project I linked below)

When doing this the reload animation does not play properly similar to 1.

https://playcanvas.com/project/876670/overview/anim

It is the same project I am playing around with. I should have asked how to get it to work rather than not working because I do not know how to do it.

The way I would do this is not to use the ANY state at all as you would need to gate transitions which becomes messy.

I would have it like this:

And instead of creating the transitions in the graph to reload, I would use the transition function on the AnimComponentLayer https://developer.playcanvas.com/en/api/pc.AnimComponentLayer.html#transition to transition from whatever state the character is in to Reload state

1 Like

To add a second solution, if you did want to use the ANY state, you’d need to keep the reload boolean to true while you’re in the reload state, then set conditions on the ANY > Walk & ANY > Idle transitions which check that reload is false. Like @yaustar mentioned, this would be gating your transitions with conditionals.

I’ve set it up as so here:
https://playcanvas.com/project/881559/overview/anim-reload

You’ll see I have updated your movement script from:

    if (app.keyboard.isPressed(pc.KEY_R) && anim.baseLayer.activeState !== 'Reload') {
        anim.setBoolean('Reload', true);
    }
    else {
        anim.setBoolean('Reload', false);
    }

to:

    if (app.keyboard.isPressed(pc.KEY_R) && anim.baseLayer.activeState !== 'Reload') {
        anim.setBoolean('Reload', true);
    }
    else if (anim.baseLayer.activeState === 'Reload' && anim.baseLayer.activeStateProgress > 0.8) {
        anim.setBoolean('Reload', false);
    }
2 Likes

Tried both solutions and both worked perfectly :smiley:

Additionally: in my code looks like I forgot to add the check for activeState === ‘Reload’ because sometimes the animation would not play after pressing R.

Thanks so much for your help Elliot and yaustar!

1 Like