Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by zak666 · Dec 13, 2017 at 11:02 AM · errornavmeshagent

Navmesh Agent Not placed on mesh?

Hi gang, I have Instantiated a navmesh Agent on a cube, both the Spawnpoint and the Baked Navmesh plane are at 0,0,0 so it should be spawning on the Navmeshplane but I'm getting the Notp laced on navmesh Error any way to fix this? "GetRemainingDistance" can only be called on an active agent that has been placed on a NavMesh. Everything is setup correctly.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.AI;
 using Photon;
 public class PlayerMove : Photon.MonoBehaviour {
 
 
     public float ShootDistance = 10;
     public PlayerShooting PlayerShoot;
     public NavMeshAgent Agent;
     private Ray ShootingRay;
     private RaycastHit shootHit;
 
     public bool TeamOne;
     public bool TeamTwo;
     private bool enemyClicked;
 
     // Use this for initialization
     void Start () {
         if (photonView.isMine == true) {
             gameObject.tag = "MyPlayer";
             Agent = gameObject.GetComponent<NavMeshAgent> ();
             Agent.GetComponent<NavMeshAgent> ();
         }
     }
 
     // Update is called once per frame
     void Update () {
         Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         RaycastHit hit;
         if (Input.GetButtonDown ("Fire2")) {
             if (Physics.Raycast (ray, out hit, 10000)) {
 
                 if (TeamOne == true) {
                     if (hit.collider.CompareTag ("TeamTwo")) {
                         enemyClicked = true;
                         Agent.Resume ();
 
                     }
                 }
 
                 if (TeamTwo == true) {
                     if (hit.collider.CompareTag ("TeamOne")) {
                         enemyClicked = true;
                     }
                 }
             } else {
                 enemyClicked = false;
                 Agent.destination = hit.point;
                 Agent.Resume ();
             }
         }
 
         if (Agent.remainingDistance <= Agent.stoppingDistance) {
             Agent.Stop ();
         } else {
             Agent.Resume ();
         }
 
 
 
         if (enemyClicked == true && Agent.remainingDistance < ShootDistance) {
             PlayerShoot.Shooting = true;
         } else {
             PlayerShoot.Shooting = false;
 
         }
 
     }
 }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Whiteleaf · Dec 13, 2017 at 03:51 PM 0
Share

I'd like to add something unrelated. It looks like you're using Photon, and you don't check if you own the photonView in update. So everyone will be able to control anything with this script on it.

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by NorthStar79 · Dec 13, 2017 at 01:59 PM

this error usually appears when nav mesh agent is not placed on navmesh area. there are some mistakes that people do often when dealing with navmesh agents. i will try to sort some of them here, I hope this helps.

first of all, placing navmesh agent below navmesh level, this usually throws this error. to avoid this, place your navmesh agent lite bit higher than navmesh (just lite bit not too much nor same level)

second, changing game objects transform after initializing, if a game objects position changes via code navmesh agent may stuck old position, thus can cause this kind of error. to solve this I Suggest using NavMeshAgent.Warp instead of changing game objects transofm.position.

another cause of this error is , sometimes navmesh data can be corrupted (after updating unity for example) if this is a problem solution is re-baking nav mesh usually.

please check this steps and inform us if you get this error again. if your problem isn't one of the mistakes I pointed here, we will help you to investigate deeper.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zak666 · Dec 13, 2017 at 02:23 PM 0
Share

Hi thanks you for replying, I have spent the last hour Trying all of these options after doing a google search for an answer. it's quiet strange I've also tried my spawnpoint for my player (testcube) at verious hights above the Plane and I have also tried resetting my PC and re-baking nothing seems to work.

avatar image NorthStar79 zak666 · Dec 13, 2017 at 04:15 PM 0
Share

its very strange, can we see screenshots from your scene,inspector and navigation settings?

and other codes that may influence navmesh agent.

oh, i need to say one more common mistake too , if you are loading your scene as additive and your player stays other scene, that will cause this error too. i was learned this one by hard way :)

avatar image zak666 NorthStar79 · Dec 13, 2017 at 04:26 PM 0
Share

I have a simple Login screen, then I load in my Player Home Base scene, and then I photon-instansiate my Players Ship. I have tried disabling ridgidbody act, but nothing seems to work... I have copied and pasted the click to move laern code to see if its my script but that to dosnt seem to work...

alt text alt text

scene11.jpg (251.6 kB)
scene1.jpg (273.6 kB)
Show more comments
avatar image anaro027 zak666 · May 24, 2018 at 05:40 PM 0
Share

How you could validate When this is going to happen is there any flag that indicate when an active agent has not been placed on a Nav$$anonymous$$esh?

avatar image anaro027 · May 24, 2018 at 05:39 PM 0
Share

How you could validate When this is going to happen is there any flag that indicate when an active agent has not been placed on a Nav$$anonymous$$esh?

avatar image Aqib_ch_dev · May 08, 2021 at 09:24 AM 0
Share

That is working for me navmesh.wrap

avatar image
1

Answer by Unshackled · Jun 26, 2019 at 02:25 PM

I found a solution by adding a tag to the floor called "floor", then adding this to the bottom of the script:

  public void OnTriggerEnter(Collider other)
     {
         if ((other.tag == "floor") && (isonfloor == false))
         {
             agent.enabled = false;
             agent.enabled = true;
             isonfloor=true;
         }
     }

It seems to reset them if they have left the ground (like when you fly-kick them).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image snowinrain · Dec 11, 2019 at 07:03 AM 0
Share

This works for me. Thanks

avatar image
0

Answer by toyhunter · Sep 02, 2021 at 06:45 AM

The error "XXX can only be called on an active agent that has been placed on a NavMesh" occurred even if your setting are 100% correct but somehow your baked navMesh was gone. What you have to do is bake that mesh again, cheers!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

103 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making NavMesh areas? 0 Answers

How to change a baked agent's size dynamically to consider children as a part of the NavMeshAgent 0 Answers

Disable and Enable NavMesh Agent Unable to Move to Destination 1 Answer

Is it possible to store NavMeshAgents paths and assign them to other NavMeshAgents later? 1 Answer

"SetDestination" can only be called on an active agent that has been placed on a NavMesh. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges