Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Kiino · Jul 22, 2014 at 08:56 AM · meshactiveagentnav

... Can only be called on an Active Agent that has been placed on a Nav Mesh?

I have no errors before I start the game but these things usually pop up a minute into run time. I know these are coming from the scrips of an Ai unit i made with a Nav Mesh Agent component. the map is fully baked as well. However I have at least 50 of these units and I only get around 3-5 of these errors.

Here is the error message...

""SetDestination" can only be called on an active agent that has been placed on a NavMesh. UnityEngine.NavMeshAgent:set_destination(Vector3)"

and here is the code where this error points to...

 function inCombatAi()
 {
     if(DEBUG)Debug.Log(inCombat);
     
     if(inCombat == false && targetObj == null && fireOnce == true)
     {    
         if(DEBUG)Debug.Log("Finding Destination");
         Nav.destination = FindClosestTarget().transform.position;
     }
     
     if(inCombat == true && targetMemory !== null && targetDes !== null && gameObject !== null && Nav !== null)
     {
         if(DEBUG)Debug.Log("Finding Target");
         var target = targetDes.transform;    
         Nav.destination = target.position;        
         
         var angleCheck = Vector3.Angle(transform.forward, target.position - transform.position) < 15;
         var distCheck = Nav.remainingDistance < range;
         var distCheckTwo = Nav.remainingDistance >= range;tin
         
         
         if(angleCheck && distCheck)
         {
             Nav.stoppingDistance = range * 0.8;
             Nav.ResetPath();
         }
         if(!angleCheck && distCheckTwo)
         {
             Nav.stoppingDistance = range * 0.1;
             Nav.ResetPath();
         }
     }
 }
 

I read around the forums (REALLY awesome community btw) and someone said that its because the object isnt on the Nav mesh and a fix would be just aligning the object right on top of the Mesh.. however these errors pop up during run time and I believe something happens that causes the unit to maybe jump up. I dont really know. If someone can help point out a way ti fix this, I would really appreciate it!

Thanks in advance!!

Comment
Add comment · Show 2
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 Klarax · Jul 22, 2014 at 10:02 AM 0
Share

i think i had this problem once, and it was down to the parent location of the prefab.

so what was happening was, the parent was somewhere random in the scene, even tho the prefab was spawning at the location. the parent threw the error as it was in a different location to where i thought it was.

I would suggest dragging the the prefab into the scene , and looking where each item is in relation to its child. i.e. click the top parent, note where that is, then child of it, then the next child etc, and see where the axis is of each is

avatar image Kiino · Jul 23, 2014 at 03:41 PM 0
Share

Ah I see what your saying. In my case, the script was attached to a unit called "$$anonymous$$ion (clone)" which came from a spawner. There are at least 50 of these units in the scene with the same name. I think when the unit dies the nav mesh agent somehow still exists and relates itself to a new spawn of "$$anonymous$$ion (clone)" since they have the same name.

The $$anonymous$$ion only has two objects, its main body (parent) and a child. although the child doesnt have any scripts on it.

What do you think?

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by pragmar · Apr 28, 2015 at 03:32 AM

Old thread, I know--but just went through the same thing. There's an unintuitive sequence of events that cause this.

1. Destoy(something)
2. something.Update event
3. something.OnDestroy event

Fortunately OnDisable seems to fire regularly between Destroy and Update.

So far, this is working --

 public class Something {
   public NavMeshAgent agent;
   public bool doUpdate;
   public Vector3 dest;
   void Start () {
     agent = GetComponent<NavMeshAgent>();
     doUpdate = true;
     dest = Vector3.zero;
   }
   void Update () {    
     if (doUpdate)
     {
       // find dest
       agent.SetDestination(dest);
     }
   }
   void OnDisable()
   {
       doUpdate = false;
   }
 }
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 Fcaldas · Jul 08, 2015 at 01:00 PM 0
Share

Got it working for me, thanks.

avatar image
0

Answer by metars · Dec 02, 2015 at 04:07 PM

Don't forget scene floor always must be static for NavMeshAgent

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Nav Mesh Agents Not working 0 Answers

Nav Mesh Agent 0 Answers

NavMesh obstacle avoidance faulty? 1 Answer

My Nav Mesh Agent won't touch its target. 2 Answers

Why Nav Mesh Agent has been baked intermittently on 1 straight component? 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