#Non-looping animation firing twice

1 messages · Page 1 of 1 (latest)

river hinge
#

Hello, I have an attack animation that is firing twice when I click the button, and I am having trouble figuring out why. I have the signal set up as a Trigger.

Here is a video. Code next.

#
public class Succubus : BoxPlayer
{
    private Vector2 _moveDirection;
    private PlayerInput playerInput;
    [SerializeField] private float speed = 5f;
    public InputActionReference move;
    public InputActionReference attack;
    public InputActionReference jump;

    new void Start()
    {
        base.Start();
        playerInput = GetComponent<PlayerInput>();
        playerInput.SwitchCurrentActionMap("Player");

        if (move != null && move.action != null)
        {
            move.action.performed += OnMovePerformed;
            move.action.canceled += OnMoveCanceled; // Optional: Handle stopping movement
        }

        if (attack != null && attack.action != null)
        {
            attack.action.performed += context => OnAttack();
        }

        if (jump != null && jump.action != null)
        {
            jump.action.performed += context => OnJump(); // Use a separate method for jump
        }
    }

    new void Update()
    {
        base.Update();

        if(MoveVector().x < 0)
        {
            SpriteRenderer().flipX = true;
        }
        else if (MoveVector().x > 0)
        {
            SpriteRenderer().flipX = false;
        }

        if(_moveDirection.x != 0 && !Animator().GetBool(State.airbourne))
        {
            Animator().SetBool("walking", true);
            RigidBody2D().linearVelocityX = _moveDirection.x * speed;
        }
        else if(_moveDirection.x == 0 && !Animator().GetBool("airbourne"))
        {
            Animator().SetBool("walking", false);
        }
    }
...
    public void Attack()
    {
        Animator().SetTrigger(State.attack);
    }

    public void OnAttack()
    {
        if(!Airbourne())
        {
            RigidBody2D().linearVelocityX = 0;
        }
        Attack();
    }

drifting valve
river hinge
#

Here is the Input mapped.

#

Player Input:

#

oh, I wonder if it is firing twice because of that

drifting valve
#

and yes it looks like you have subscribed the method twice

#

once in your code, once on the PlayerInput component

river hinge
#

yup it looks like that was the culprit.

#

Could you help me understand what you are asking for by "configuration"?

drifting valve
#

I meant to click on this

#

and show me what was on the right side

river hinge
#

The action properties?

drifting valve
#

yep

#

it's a moot point now

#

but if it was set to "Pass Through", for example, that could have been another reason.

river hinge
#

for sure. I wanted to make sure I could get the info people want who are trying to help me in future, you know?