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 lattman · May 19, 2015 at 10:00 AM · unity5pathfindingupgradeinstantiated

Issue with pathfinding after upgrade to Unity 5

I upgraded my project from Unity 4.6 and followed the steps for rebaking my navmesh. It is a simple quad navmesh with no obstacles used for nav mesh agents. My player object is not controlled with a Nav Agent but through update through the use of getting user Input. The problem is if I continuously move my player the enemies spawned in the scene through Instantiate appear to wait before beginning to pathfind to the the player even though I can see that their SetDestination is called. Even after they start moving, if player movement resumes heavily their velocity seems to slow and they appear to be waiting. I have the pathfinding use SetDestination from a Coroutine every 1/3 second or so, increasing or decreasing has not solved the issue. I also tried adding a call to navAgent.Resume() after the path is reset (I read in the docs that this has to manually be done in unity 5 but it didn't solve the problem). In unity 4.6, my enemies immediately began pathfinding to the player regardless of player movement. I have isolated the code below. I have also found that Nav Agents preloaded in the scene will pathfind normally, the problem is only occuring with the pathfinding prefabs that are instantiated into the scene during runtime. Has anybody else run into this issue?

 public class PlayerController : MonoBehaviour {
 
     public float speedx, speedz;
     
     private void ComputerControls()
     {
 
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
         Vector3 movement = new Vector3(moveHorizontal * speedx, GetComponent<Rigidbody>().velocity.y, moveVertical * speedz);//using the current velocity for y
         
         GetComponent<Rigidbody>().velocity = movement;
 
     }
 
     
     void Update () {
             ComputerControls();
     
     }
     
 
 }




nav agent script

 public class NavScript : MonoBehaviour {
     
     private PlayerController player;
     private NavMeshAgent nav;
 
 
     // Use this for initialization
     void Start () {
         nav = GetComponent<NavMeshAgent>();
         
         player = GameObject.FindWithTag ("Player").GetComponent<PlayerController>();
 
         StartCoroutine (LookForPlayer ());//begin looking for player
 
 
     }
 
 
     protected virtual IEnumerator LookForPlayer(){
 
         while(true){
             nav.SetDestination (player.transform.position);
             yield return new WaitForSeconds(0.3f);
         }
     }
     
     
 }
 

alt text

screenexample.png (65.3 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by lattman · May 18, 2015 at 11:22 PM

I may have discovered the issue. After much trial and error, I found that deselecting "auto breaking" on the NavMeshAgent allowed the prefab agent to immediately start pathfinding. I do not know why the instantiated prefab behaves differently than the prefab placed in the scene before run-time, but apparently there is some difference.

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

2 People are following this question.

avatar image avatar image

Related Questions

Unity New UI system not working after the project is upgraded 5 Answers

Two-dimensional array of game objects to create a graph of nodes? 0 Answers

Unity 5 upgrade broke lightmapped shader 1 Answer

Upgrading from 4 to 5 0 Answers

A* pathfinding generating new path when created new obstacle 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