Error with navAgent.velocity

Hi all

I am getting an error message with this script, that I never got before when I used it in another project that has since been deleted.

Here is the script:

using UnityEngine;
using System.Collections;
using BehaviorDesigner.Runtime;
//using UnityEngine.AI.NavMeshAgent;


public class MovementScript : MonoBehaviour
{
    //link to Animator component
    public Animator animController;
    //used to set anim controller parameters
    public enum MoveState { Idle,Walking,Attack}
    public MoveState moveState;
    //link to NavMeshAgent component
    public UnityEngine.AI.NavMeshAgent navAgent;
    public BehaviorTree behaviorTree;
    private bool canSeePlayer;
    private bool canAttack;
    public float damageAmount;
 

    public void Start()
  
    {
        canSeePlayer = ((SharedBool)behaviorTree.GetVariable("Chase")).Value;
        canAttack = ((SharedBool)behaviorTree.GetVariable("Attack")).Value;           
     
    }
   
    // Update is called once per frame
    void Update()
    {
        //character walks if there is a navigation path set, idle all other times
        canSeePlayer = ((SharedBool)behaviorTree.GetVariable("Chase")).Value;
        canAttack = ((SharedBool)behaviorTree.GetVariable("Attack")).Value;



        if (canSeePlayer)

        {
            moveState = MoveState.Walking;
            print(moveState);
            print("I see you!");

            if (canAttack)
            {
                print("Attacking you!");
                moveState = MoveState.Attack;

            }


        }
        else
        {
            moveState = MoveState.Walking;
        }
              
        //send move state info to animator controller
        animController.SetInteger("MoveState", (int)moveState);

    }
    void OnAnimatorMove()
    {
        //only perform if walking
        if (moveState == MoveState.Walking)
        {
            print("In OnAnimatorMove Function");
            //set the navAgent's velocity to the velocity of the animation clip currently playing
            navAgent.velocity = animController.deltaPosition / Time.deltaTime;
          
            //smoothly rotate the character in the desired direction of motion
           Quaternion lookRotation = Quaternion.LookRotation(navAgent.desiredVelocity);
           transform.rotation = Quaternion.RotateTowards(transform.rotation, lookRotation, navAgent.angularSpeed * Time.deltaTime);
        }
    }
  
   
}

Here is the error that I am getting,

navmeshagent.velocity assign attempt for ‘creature1’ is not valid. Input velocity is { NaN, NaN, NaN }.
UnityEngine.AI.NavMeshAgent:set_velocity(Vector3)
MovementScript:OnAnimatorMove() (at Assets/Scipts/MovementScript.cs:71)

I am not sure why I am getting this and I am a basic C# coder, so I am not sure what NaN is, though I found in the Unity Answers it refers to Not A Number?

If I comment the navAgent.velocity line the code runs and my Agent moves but very quickly and I don’t get the error.

When I used this script in another project, I am sure I didn’t get this error.

This script is used with Behavior Designer in order to move an Agent across a NavMesh and to control which animation is played based on the Agent seeing the player and attack the player.

Thanks for any help

Maybe Time.deltaTime is 0, either through Time.scale being 0 or some other event, such that you’re dividing by zero resulting in NaN. That’s my only guess.