Getting remaining distance from navmesh agent if navmesh agent is disabled

I need to check if the remaining distance for the navmesh agent to get to the player is below certain length before enabling the navmesh agent, otherwise, I want the navmesh agent to remain disabled and have the enemy go directly towards the player and just break through any obstacles between the enemy and player instead of going around using navmesh. However, to get the Agent.remainingDistance, the agent has to be enabled first, which I don’t want it to be as then the enemy goes around obstacles instead of breaking through.

Here is the code I have so far, but as I get an error at the “if(Agent.remainingDistance < DistanceToTarget + OutOfWayDistance)” statement because the navmesh agent is disabled.

if(Physics2D.Raycast(transform.position, Direction, DistanceToTarget, NavMeshLayer))
            {
                if(Agent.remainingDistance < DistanceToTarget + OutOfWayDistance)
                {
                    Agent.SetDestination(Target.position);

                    if(Agent.enabled == false)
                    {
                        Agent.enabled = true;
                    }

                    if(NavControl == false)
                    {
                        NavControl = true;
                    }
                }
                else
                {
                    if(NavControl == true)
                    {
                        NavControl = false;
                    }

                    if(Agent.enabled == true)
                    {
                        Agent.enabled = false;
                    } 
                }
            }
            else
            {
                if(NavControl == true)
                {
                    NavControl = false;
                }

                if(Agent.enabled == true)
                {
                    Agent.enabled = false;
                }
            }
        }

If I get you right, you can just do

float distance = Vector3.Distance(target.transform.position, Agent.transform.position);

        if(distance <= range)
        {
            enemy.enabled = true
        }

Where range is the ‘certain length’
And in the start just set Agent.enabled to false.
Is this what you wanna do, cause I got no idea what’s happening in your code