• 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 Tonytalent · Aug 27, 2015 at 12:26 PM · ainavmeshnavmeshagent

Many navmesh agents makes causes them to freeze/creates delay with input

I have navmesh agents that chase and others that flee. When I have more than 150-200 navmesh agents in my scene, they all seem to freeze for a moment before setting their new "fleeing destination". Strangely, the game doesn't lag at all, only the navmesh agents' behavior does. It's as if there were too many paths to compute and they just can't deliver.

The way my system works, each agent has a big sphere collider which, from the point of view of a fleeing agent, stores the incoming pursuer into a list and then goes over each pursuer in this list (with a foreach loop) to determine which one is the closest and where to run in the opposite direction. The functions are called with InvokeRepeating("Class",0,0.5f).

It really bugs me because I've tried changing the whole system so that it uses coroutines primarily but that only accentuated the agent freezing (with visual game-wide lag this time).

The profiler and google haven't been of much help either. I could really use a hand.

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 Foulcloud · Sep 23, 2017 at 04:04 AM 0
Share

Same problem here. CPU load and framerate ok. Navigations pause after larger number of agents (150+). $$anonymous$$y agents are simply following navmesh path to where the player is.

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Foulcloud · Sep 23, 2017 at 05:19 AM

NavMesh.SetDestination is an asynchronous call but I don't think it is multi threaded. So I am guessing if the core this is using gets maxed out then it throws stuff in a queue and "gets around to it" when there is time/CPU.

My fix was to replace NavMesh.SetDestination with NavMesh.CalculatePath. Create a new path, set your agent to the new path and update the path periodically with NavMesh.CalculatePath. This is not asynchronous and you might lose a little performance.

Now your agents will not stop when system is taxed. Also, you can rely on the path and time the agent takes to get to the destination being consistent. Thinking of "Tower Defence" games where this would be critical.

Comment
Add comment · Show 2 · 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 ugurtunakoca · Dec 18, 2021 at 01:26 PM 0
Share

Man, I was trying to figure out "why my wild animals are staying a while when they should run away?" for days I rewrote my codes, tried a lot things to understand the problem. Your solution worked beautifully! Thank you.

avatar image johjitest · Apr 02 at 08:13 AM 0
Share

Brilliant answer! solved it for me.

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

6 People are following this question.

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

Related Questions

NavMesh Agent Obstacle Avoidance Ignore 1 Answer

How to add variables to Components (Nav Mesh Agent)? 0 Answers

How to make AICharacterController able to walk on walls and ceilings? 0 Answers

What’s the simplest way to find nearest navmesh targets? 0 Answers

Move NavMeshAgent at a constant speed 1 Answer


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