Stop animation on character

Silver100

Member
Hi,

Hope you can help I'm trying to stop animation & also head bobbing in runtime on my player. The following (for animation stop) is not responding. I also struggle with the state system so was looking at a more easier solution.

Code:
            var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
            var StopanimAbility = characterLocomotion.GetAbility<StopMovementAnimation>();
                                                                
                                                                   
            characterLocomotion.TryStartAbility(StopanimAbility);

            {
                characterLocomotion.TryStartAbility(StopanimAbility);
        }
        }
    }
 
Last edited:
I recommend placing a breakpoint within StopMovementAnimation.CanStartAbility method to determine why it's not starting.
 
Thanks,

I'm getting a response; Null ref exception Object ref not set to instance of object although I have tried on player and player directly associated with the animator.

I tried both update and start methods and set up as image below even tried AutoStart on ability in the inspector, which usually activates most abilities on start up. Not sure where I have gone wrong here may have missed a setting or made an error somewhere?
Code:
using UnityEngine;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities;


public class Playeranimfreeze : MonoBehaviour
{
 
    [Tooltip("The character that should start and stop the speedchange ability.")]
    [SerializeField] protected GameObject m_Character;
    // Start is called before the first frame update
    void Start()
    {
 
    }

    // Update is called once per frame
    void Update()
    {
        Debug.Log ("Stop anim");
        var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
        var StopanimAbility = characterLocomotion.GetAbility<StopMovementAnimation>();


        characterLocomotion.TryStartAbility(StopanimAbility);

        {
            characterLocomotion.TryStopAbility(StopanimAbility);
        }
    }
}
 

Attachments

  • Animstopability.png
    Animstopability.png
    90.6 KB · Views: 3
Last edited:
Please remove your regular text from the "[ code ]" tag as it's hard to read. What is the call stack of the null reference?
 
Top