Walking animation no longer works

The walking animation hasn’t been working for me for a while, but having got through the course I’ve decided to go back and figure out what’s wrong, and I’m going crazy.

From what I can tell from the animator, the transition from Rifle Aiming Idle to Rifle Run is not working - the idle animation continues to play while the unit moves. It worked fine before the UnitAnimator script was created.

From UnitAnimator:

private void Awake() 
    {
        if (TryGetComponent<MoveAction>(out MoveAction moveAction))
        {
            moveAction.OnStartMoving += MoveAction_OnStartMoving;
            moveAction.OnStartMoving += MoveAction_OnStopMoving;
            moveAction.OnChangedFloorsStarted += MoveAction_OnChangedFloorsStarted;
        }

// later

private void MoveAction_OnStartMoving(object sender, EventArgs e)

    {

        animator.SetBool("IsWalking", true);

    }

    private void MoveAction_OnStopMoving(object sender, EventArgs e)

    {

        animator.SetBool("IsWalking", false);

    }

So I’m sure the string matches just fine. I’ve also run a debug.log to check MoveAction_OnStartMoving is firing, and it is. The Jump and Drop animations from the bonus multifloor section of this course also work from within this script, as does the shoot animation.

I’ve tried placing the UnitAnimator in various places in project settings script execution order, and it makes no difference.

Here’s the relevant parts of the MoveAction script:

public event EventHandler OnStartMoving;
public event EventHandler OnStopMoving;

// later

public override void TakeAction(GridPosition gridPosition, Action onActionComplete)
    {
        List<GridPosition> pathGridPositionList = Pathfinding.Instance.FindPath(unit.GetGridPosition(), gridPosition, out int pathLength);

        currentPositionIndex = 0;
        positionList = new List<Vector3>();

        foreach (GridPosition pathGridPosition in pathGridPositionList)
        {
            positionList.Add(LevelGrid.Instance.GetWorldPosition(pathGridPosition));
        }

        OnStartMoving?.Invoke(this, EventArgs.Empty);

        ActionStart(onActionComplete);
    }

Any idea as to what is going wrong?

Quick rule of thumb, don’t let it get to the end, fix it where it broke. Bugs are much easier to squash when they are larvae than when they become fully grown and part of the main program. :slight_smile:

So I want to make sure I have all the parameters…

  • The Walking animation does not play.
  • MoveAction_OnStartMoving is firing. as evidenced by a Debug.Log within MoveAction_OnStartMoving.
  • The correct variable in the inspector is a boolean variable named “IsWalking”

Things left to check:

  • With the character’s Animator GameObject selected, open the Animator in a window visible to while you play. Make sure that IsWalking is turning on and off within the Animator Window.
  • Check the transitions to and from IsWalking
    • Are they set to IsWalking True and IsWalking False?
    • Does the transition have a “Has Exit Time” checked? (turn this off for both transitions)

You are both starting and stopping the animation when starting to move

Thanks

The transitions are set up correctly, but the IsWalking bool is not turning on and off that I can see.

I saw the comment below yours mentioning that both the start walking and stop walking might be triggering together, so perhaps it’s turning on and off instantly. I’m sure that’s how it was written in the tutorial, but I’ll check.

They might not be triggering together, they are. You have hooked the StopMoving handler to the StartMoving event, so the StartMoving handler is run to start the animation and the StopMoving handler is also run - when you start moving - to stop the animation again. It’s a simple mistake that anyone could make, but it has been made. Just change it to moveAction.OnStopMoving += MoveAction_OnStopMoving

It’s not. In the lecture it is correct
image

Ah my apologies, I misread what you said - it’s clearly a typo on my part. Thanks!

No need to apologise. I just read my last post again and realised it ‘sounds’ a bit angry. I should be the one apologising.

Fixing the above should fix your problem

It’s an easy mistake to make, and tricky to spot.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms