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
0
Question by p_unity · Mar 10, 2015 at 11:09 PM · ainavmeshnavmeshagentpathfinding

NavMesh Agent not updating (Setting) new path

Im using the NavMesh agent to move my "Inhabitants" around the scene. The desinations are set depending on what time of day it is. There are three destinations at present, a "Home" a "Work" and a "Hobbies" location.

Now the code is getting called, s the debugs and text is being called correctly. BUT the actual pathfinding isnt updating and they stay in the same place even when we move on to another part of the day.. Havny really used NavMesh pathfinding before, so might be simple. But as far as im aware calling the SetDestination method of the NavMesh Agent is all you need to do to update the path.

Heres the code.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;    
 
 // Now using unity built in nav mesh for pathfinding.
 public class NavMeshPathfinding : MonoBehaviour {
 
     public enum Destinations{
         
         home,
         work,
         hobbies
     };
     
     Destinations destination;
 
     // The actual destinations in the scene.
     public GameObject home;
     public GameObject work;
     public GameObject hobbies;
     public Text destinationText;
 
     NavMeshAgent agent;
 
     private GameObject GM;
 
     private WorldTime worldTime;
 
     // Use this for initialization
     void Start () {
 
         agent = GetComponent<NavMeshAgent>();
         GM = GameObject.FindGameObjectWithTag(Tags.GM);
         worldTime = GM.GetComponent<WorldTime>();
 
         destinationText.text = "Idle";
     
     }
     
     // Update is called once per frame
     void Update () {
 
         // when its a weekday..
         if (destination != Destinations.home && (worldTime.timeOfDay == WorldTime.TimeOfDay.Morning || worldTime.timeOfDay == WorldTime.TimeOfDay.Nightime) )
         {
             
             destination = Destinations.home;
             GetNewDestination();
 
         }
         
         else if (worldTime.day == WorldTime.Days.Saturday || worldTime.day == WorldTime.Days.Sunday)
         {
             
             if (destination != Destinations.hobbies && worldTime.timeOfDay == WorldTime.TimeOfDay.WorkTime)
             {
                 destination = Destinations.hobbies;
                 GetNewDestination();
             }
             
         }
         
         
         else
         {
             if (destination != Destinations.work && worldTime.timeOfDay == WorldTime.TimeOfDay.WorkTime)
             {
                 
                 destination = Destinations.work;
                 GetNewDestination();
             }
             
         }
     
     }
 
     public void GetNewDestination ()
     {
 
         if (destination == Destinations.home)
         {
             Debug.Log("Heading to" + destination);
             agent.SetDestination(home.transform.position);
             destinationText.text = "Heading home";
         }
 
         else if (destination == Destinations.work)
         {
             Debug.Log( "Heading too "+ destination);
             agent.SetDestination(work.transform.position);
             destinationText.text = "Time for work";
         }
 
         else if (destination == Destinations.hobbies)
         {
             Debug.Log("Heading to: "+destination);
             agent.SetDestination(hobbies.transform.position);
             destinationText.text = "Now for some me time.";
         }
 
     }
 }
 

So they head to the inital desination "home" and then stay there..

So what am i doing wrong troops?

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 siaran · Mar 10, 2015 at 11:20 PM 0
Share

hmm, strange, I don't see anything wrong, and calling SetDestination should have agents recalculate their paths as far as I'm aware...it's late here and I probably shouldn't be trying to answer things on the forums half asleep but...have you tried calling RecalculatePath() after you change an agents destination?

avatar image p_unity · Mar 11, 2015 at 11:01 AM 0
Share

hey bud. RecalculatePath needs a "Path" parameter, im pretty sure, and the destinations are Vectors. I dont know how i can make the destinations a path ins$$anonymous$$d of a Vector, or even if you can..

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DanSuperGP · Mar 10, 2015 at 11:21 PM

In Unity 5, NavMesh Agents will not automatically resume when a new destination is set. You need to manually call Resume()

This is noted in the Unity 5 Upgrade Guide http://docs.unity3d.com/Manual/UpgradeGuide5-AI.html

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 p_unity · Mar 11, 2015 at 11:02 AM 0
Share

Im using 4.6.1. SetDestination shoukd overwrite any existing paths as far as i know.. i dont get it. any other suggestions?

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

Possible to edit the movement of NavMeshAgent ? 2 Answers

Ignoring or overruling a NavMeshAgent destination 0 Answers

NavMesh Agent glitches in trees 3 Answers

Editing NavMesh Paths? 0 Answers

Horde of NavMeshAgents - stops to recalculate path. 4 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