- Home /
SetDestination function error
Hi, I was creating game by this tutorial: https://www.youtube.com/watch?v=xUl-Agx2cLc and I got stucked when script from them doesn't work as it should. I get error "SetDestination" can only be called on an active agent that has been placed on a NavMesh. " with this script:
Here is whole code (most of functions are disables until I make these things (as in tutorial where I'm learning from)):
using UnityEngine;
using System.Collections;
public class EnemyMovement : MonoBehaviour
{
Transform player;
//PlayerHealth playerHealth;
//EnemyHealth enemyHealth;
NavMeshAgent nav;
void Awake ()
{
player = GameObject.FindGameObjectWithTag ("MyPlayer").transform;
//playerHealth = player.GetComponent <PlayerHealth> ();
//enemyHealth = GetComponent <EnemyHealth> ();
nav = GetComponent <NavMeshAgent> ();
}
void Update ()
{
//if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0)
//{
nav.SetDestination(player.position);
//}
//else
//{
// nav.enabled = false;
//}
}
}
I hope someone has an idea how to fix it because my enemy doesn't move there where I am but just enemy keeps his position all the time.
Have you tried moving the position of the enemy down slightly to ensure it is actually on the Nav$$anonymous$$esh?
That error is telling you that you are indeed attempting to set the destination (move) an agent without being on a Nav$$anonymous$$esh, ensure your agent is close enough to the Nav$$anonymous$$esh and that you have it baked correctly.
Sorry but I actually don't understand what should I change exactly...Can you tell me what should I exactly change to do that what you're talking about?
The enemy object you have that is in the scene you are trying to move, make sure that is down on the ground level with your Nav$$anonymous$$esh almost.
Here is a similar issue:
Bro, its easy to see from your screenshots you haven't baked a Nav$$anonymous$$esh onto that scene. If you had the walkable areas would be blue. Like someone already told you, you haven't finished setting up that scene to work with Nav$$anonymous$$eshAgents, look at the tutorial he linked to you.
What does it mean I haven't baked a Nav$$anonymous$$esh onto that scene and how to fix it? After watch tutorial I still don't understand :/
Ohh, I've just noticed there is button to bake it. I didn't see this. Thank you so much guys!
Your answer
Follow this Question
Related Questions
CharacterController not found the GameObject 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
my enemy is broken 1 Answer
what is wrong whis this? 1 Answer