• Register
0 votes

Problem :

I am new to Unity5. I am facing following error while trying to do setDestination.

"SetDestination" can only be called on an active agent that has been placed on a NavMesh. UnityEngine.NavMeshAgent:SetDestination(Vector3) CompleteProject.EnemyMovement:Update() (at Assets/_CompletedAssets/Scripts/Enemy/EnemyMovement.cs:30)

Please find below my code for your reference.

using UnityEngine;

using System.Collections;

namespace MyCompleteProject


    public class MyEnemyMovement : MyMonoBehaviour


        Transform players;              

        PlayerHealth playerHealths;     

        EnemyHealth enemyHealths;       

        NavMeshAgent navs;              

         void Awake ()


         players = GameObject.FindGameObjectWithTag        ("Player").transform;

            playerHealths = players.GetComponent <PlayerHealth>  ();

            enemyHealths = GetComponent <EnemyHealth> ();

            navs = GetComponent <NavMeshAgent> ();


       void Update ()



            if(enemyHealths.currentHealths > 0 &&     playerHealths.currentHealths > 0)


              navs.SetDestination (players.position);





               navs.enabled = false;






May I know what is wrong with the above code? Does anyone have any solution on my issue?

6 5 3
7,540 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I have lots of industry experience in writing complex Unity5 code.

I have gone through your post and understood your problem.

So to begin with you must follow below approach to resolve your issue:

1. Please make sure that your thirdPersonController is above the ground.

2. Please go to the Window->Navigation->Bake and click on  bake.

The blue area is where the thirdperson can reach in the ground.

9 7 4
38,600 points
0 votes


STEP 1: You need to add a Navmesh to your scene before you can use NavMeshAgent or anything else related to Navigation.

STEP 2: Ensure that your thirdPersonController is above the ground.

STEP 3: .Go to Window->Navigation->Bake and click bake.The blue area is where the thirdperson can reach in the ground.

STEP 4: Your floor (plane or quad) must be static.

STEP 5: Add NavmeshAgent component your player or your enemy.

You can find static checkbox on inspector panel

STEP 6: 

If you create a NavMeshAgent and set its position via transform.position=... and then try to SetDestination, it fails because the NavMeshAgent did not recognize the position change and does not know that it already is on the NavMesh. Use NavMeshAgent.Warp instead of transform.position to initialize the position before calling SetDestination.


set up some params (The tutorial has Radius=0.75, Height=1.2 and Step Height=.0.1, and the rest of the settings from the tutorial are gone in Unity 5, as far as I can tell.

STEP 8: Follwing code will slove this problem

nav.enabled = false;


10 6 4
31,120 points
problem fixed here : https://youtu.be/O8ekMrd33P8

Related questions

0 votes
1 answer 402 views
Problem : I am trying to create the test app using unity but facing following issue: readpixels was called to read pixels from system frame buffer, while not inside drawing frame.
asked Nov 14, 2019 peterlaw 6.9k points
1 vote
3 answers 1.5K views
Problem : I am very new to unity. Recently I had updated my unity from the earlier unity5 to the current 2018.2.2f1. And after that update my Unity scripts are not at all loading. I had also tried to play my Scene but my scripts are not at all loading and I am ... time on fixing above error but still unable to fix it so looking for the expert help who can help me in fixing my issue in less time.
asked Apr 10, 2020 morrisBson 3.2k points
1 vote
2 answers 82 views
Problem: I am beginner to C# with Unity engine. I have already started learning C# with Unity engine. I have tried to write the very basic script as shown below for your reference: using UnityEngine; using System.Collections; public class scriptMyBall : MonoBehaviour { / ... but unable to fix the Unity Engine related error. I need Unity Engine&rsquo;s expert who can guide me in fixing above error.
asked May 23, 2020 Martin K 6.6k points
0 votes
1 answer 240 views
Problem : I am very new to C#. I have written the below C# code. void UpdateAxis () { float myxP = Input.GetAxis ("Horizontal")*Time.deltaTime * 20; transform.Translate (Vector3(myxP,0,0));//error is here transform.position.x = Mathf.Clamp (transform. ... the above code. error : Expression denotes a type', where avariable', value' ormethod group' was expected` Kindly suggest the solution if any.
asked Dec 3, 2019 alecxe 7.5k points
1 vote
1 answer 208 views
Problem : Looking for the solution on bellow problem setting the parent of a transform which resides in a prefab is disabled to prevent data corruption
asked Nov 8, 2019 peterlaw 6.9k points
0 votes
1 answer 113 views
Problem : I am facing following c# socket issue the i/o operation has been aborted because of either a thread exit or an application request
asked Nov 16, 2019 peterlaw 6.9k points
0 votes
1 answer 1.3K views
Problem : I want to send a JSON to elasticSearch. I am trying using Postman and SOAPUI The data I am using is as follows: [{"column1": "abc", "column2": "def", "column3": "dghi", "column4": "jkl", "column5": "mno"}, {"column1": "pqr", "column2": "stu", "column3" ... "def", "column3": "dghi", "column4": "jkl", "column5": "mno"} Then it works fine. I am unable to understand that what is going wrong.
asked Nov 20, 2019 peterlaw 6.9k points
0 votes
1 answer 124 views
Cannot create controller in thread that did not call Looper.prepare () What does the following exception mean? How can I fix it? Here is the code: Toast toast = Toast.makeText (mContext, "Something", Toast.LENGTH_SHORT); This is the exception: Java.lang.RuntimeException: Cannot ... :121)      on Android.widget.Toast. <init> (Toast.Java:68)      on Android.widget.Toast.makeText (Toast.Java:231)
asked Aug 17, 2020 game 4.6k points
0 votes
1 answer 48 views
Problem: I have only fundamental knowledge about Android. I am simply trying to execute the test for the android app but I am facing the below error. I want to know the cause and solution for the below android error. java ... at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
asked Aug 25, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 1.2K views
Problem: I am new, I need help, can anyone help me by filling in the blanks? The ________ built-in function is used to read a number that has been typed on the keyboard? A. get() B. input() C. keyboard() D. read()
asked Feb 19, 2020 maddi86 5.4k points