Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by stefanplc · Feb 05, 2018 at 08:47 PM · navmeshnavmeshagentobstaclenav meshnavagent

Update the navmesh after carving

Hi there, I'm trying to have my characters act as Nav Mesh Agents when they're moving but as Obstacles (with carving) when they're standing still so that other characters go around them instead of pushing them aside. Each character has both the Agent and Obstacle component on in and it just enables/disables the one that's required. When I set a destination for the Agent, I also spawn an empty gameObject at the destination point that has a Collider. When the character Collider hits the destination one, it switches from the Agent to the Obstacle as it knows it no longer needs to move.

The issue I'm having though is that when I set a new destination for the Agent, so basically I turn the Obstacle off, turn the Agent on and tell it its new destination, instead of moving from its current location it sort of jitters a little bit to a new position close nearby and goes from there instead. That's because the Nav Mesh updates itself briefly. Previously, it was being carved by the Obstacle component and now it no longer does that since the Obstacle is diabled.

If I add a 0.25 second delay between disabling the Obstacle and enabling the Agent all works well, but I assume that's not the proper way to do it. I've been searching online for similar posts, however I can't seem to figure out what the code syntax is to either manually call the nav mesh update so I can place it between the components switch or to add a call-back for when the nav-mesh finished updating so I can enable the agent then.

Can anyone please help? Thanks!

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 Harinezumi · Feb 06, 2018 at 12:46 PM

I don't have a definitive answer, only ideas, but some may help...
Maybe checking if the path is valid and only starting the agent then (setting velocity to > 0), would work? You can get the path either directly from the NavmeshAgent, or through CalculatePath(), and check if the path is complete.
You could also wait for NavmeshAgent.isOnNavMesh to become true.
Finally, maybe Unity's Navmesh components can help with this?

Comment
Add comment · Show 3 · 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 stefanplc · Feb 06, 2018 at 12:48 PM 0
Share

I really like the path being valid or navmesh agent being on navmesh ideas, I'll try them out, thank you!

avatar image stefanplc · Feb 07, 2018 at 03:10 PM 1
Share

Hey Harinezumi, I have tried your suggestions and the issue is that if the Nav$$anonymous$$eshAgent is enabled while it's not sitting on the Nav$$anonymous$$esh, it gets teleported to the closest possible area on the Nav$$anonymous$$esh. So unfortunately, getting a path or checking if the Nav$$anonymous$$eshAgent is on a mesh can't work. The Nav$$anonymous$$eshAgent can only be enabled after the Nav$$anonymous$$esh has been updated and the carving from the obstacle has already been removed.

So the conclusion is that I still need to figure out somehow when the Nav$$anonymous$$esh has been updated or call the update manually. I have found the following: https://docs.unity3d.com/ScriptReference/AI.Nav$$anonymous$$eshBuilder.UpdateNav$$anonymous$$eshData.html but I can't really make sense or figure out how to write it. I have public Nav$$anonymous$$eshSurface $$anonymous$$yNav$$anonymous$$eshSurface; declared and assigned through the inspector. So I can get the data via $$anonymous$$yNav$$anonymous$$eshSurface.nav$$anonymous$$eshData. I can also get the build settings via $$anonymous$$yNav$$anonymous$$eshSurface.GetBuildSettings and bounds through $$anonymous$$yNav$$anonymous$$eshData.sourceBounds but I have no idea how to add $$anonymous$$yNav$$anonymous$$eshSurface as one of the sources :(

avatar image Harinezumi stefanplc · Feb 07, 2018 at 03:33 PM 0
Share

Interesting! This is a new API since Unity 5.6, and it wasn't even announced as a feature!
Reading the (worse than usual) scripting manual for it, it seems the key is giving UpdateNav$$anonymous$$eshData() a list of Nav$$anonymous$$eshBuildSources, which can be automatically created using Nav$$anonymous$$eshBuilder.CollectSources().
However, I haven't tested this, and the API seems very experimental (there is basically no more information about how it works, what it does), so I don't know how well it works, what are the limitations, etc.

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

129 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 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

NavMeshAgent freeze for a moment 0 Answers

I have patches on nav mesh 0 Answers

for nav mesh agent, why is it that the base offset is 1 instead of 0 as default and why is setting it to 0 make the cylinder colider move down? 0 Answers

Navmesh Question A way to rebake Navmesh after destroying obstacle 1 Answer

How to spawn a navmeshagent on a certain nav mesh? 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