- Home /
NavMesh SetDestination Issue
Ive developed a Multiplayer game, but I've some issues: when a player dies, enemies has to move to the other player, and when it happens, emulator stops and returns error ""SetDestination" can only be called on an active agent that has been placed on a NavMesh". so the emulator is paused, and if i let it continue, all will go properly. This doesn't happen on the built version of the game.
Whats throwing the error? The enemy or the player? (To find out double click the error in the Console and it will take you to the line of code that was the issue.) ALSO: Some errors will cause Unity to choke, others will just cause the script to choke. If you have 'Error Pause' toggled on for the Console, it will stop test mode when it runs across any error. The toggle button is located along the top edge of the Console Window in the Editor. In addition to this, null checks are not evil.
Nav$$anonymous$$eshAgent agent;
void Awake()
{
agent = GetComponent<Nav$$anonymous$$eshAgent>();
}
void Update()
{
if (agent != null && agent.isOnNav$$anonymous$$esh)
{
agent.$$anonymous$$ove(/*$$anonymous$$y $$anonymous$$ovement Vector*/);
}
}