NullReferenceException error with navMeshAgent

Hi guys,

Hopefully a quick one. I’ve tripped myself up and struggling to see where I’ve gone wrong. I’m getting an error with this particular block of code;

        navMeshAgent = gameObject.AddComponent<NavMeshAgent>();
        navMeshAgent.speed = navMeshSteeringSpeed;
        navMeshAgent.stoppingDistance = navMeshStoppingDistance;
        navMeshAgent.updatePosition = true;
        navMeshAgent.updateRotation = false;
        navMeshAgent.stoppingDistance = stoppingDistance;
        navMeshAgent.autoBraking = navMeshAgentBraking;

I’ve managed to complete all the previous challenges to do with AddRequiredComponents but for some reason this is tripping me up. Any advice?

Privacy & Terms