• 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
0
Question by shokri · Nov 24, 2015 at 04:30 PM · navmeshnavmeshagentpathfindingcontroltraverse

Is there any way to cancel an OffMeshLink while the agent is on it already and waiting for it to be completed?

Hi, is there any way to cancel an OffMeshLink while the agent is on it already and waiting for it to be completed?
Well, I know that my question is vague so please let me describe it through an example.

OK here is my scenario: I have two rooms (room A and room B) which are connected via a door. Also I have a keypad on the wall of room A which unlocks the door. I’ll find this keypad later, using a script that is attached to the door. Finally I have an agent that I want to move him from room A to room B. The door may be locked, so the agent should check the door and if it’s locked, he should change his way to the keypad, which is on the wall, to unlock the door and then continue his way through the door to reach room B.

Here is my approach: I’ve connected both rooms NavMesh together via an OffMeshLink. Tending to move the agent, I set the destination to room B. Not to mention that I’ve turned off NavMeshAgent.autoTraverseOffMeshLink so I can handle the movement myself. I check if there’s any OffMeshLink through the path using NavMeshAgent.nextOffMeshLinkData. This way I can access to the door and its script to find out if it’s locked or not:

  • If the door isn’t locked, then on the moment of reaching the door, the agent will pass through the door simply (I’ll complete the OffMeshLink after my movement using NavMeshAgent.CompleteOffMeshLink).

  • If the door is locked, then the agent will change his way toward the keypad (I’ll reset the destination to the keypad position). He will invoke the keypad to unlock the door and then continue his way toward the door and finally the other room (I’ll reset the destination back to room B).

Now the problem is that if the agent is near the OffMeshLink already when I set the destination to room B, then NavMeshAgent.nextOffMeshLinkData won’t get me valid information regarding the OffMeshLink, because he’s currently on the OffMeshLink and there isn’t any other OffMeshLink along the way. However, NavMeshAgent.isOnOffMeshLink is false unless I set the destination. It means there’s no way for me to find out about the door status before reaching the OffMeshLink. In this situation the agent will freeze until I complete the OffMeshLink, which is awkward (Passing through an unlocked door?! It’s ridiculous).

I thought maybe I’d to cancel the OffMeshLink and set the destination to the keypad, but unfortunately there is no way to cancel an OffMeshLink while the agent is waiting for it to be completed.

What’s the solution? Should I follow another approach? I’m thinking of using two OffMeshLinks instead of one and put each one on one side of the door, but it seems to dirty. Any help would be appreciated.

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
2

Answer by zakirov78 · Jan 09, 2017 at 07:49 PM

NavMeshAgent.Warp to the same position helped me to reset isOnOffMeshLink flag.

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 SlySIy · Jul 12, 2018 at 03:48 PM 0
Share

Wow nice trick dude! Thanks a lot, you saved me so much time! :)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

37 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

Related Questions

How to exclude certain navmesh obstacles on runtime? 2 Answers

Second NavMesh Surface refuses to cooperate: Failed to create agent because it is not close enough to the NavMesh 0 Answers

Is there a way to modify my script a path, before setting it to a NavmeshAgent 0 Answers

[Unity .3.03f] NavMeshAgent stops after rebaking NavMeshSurface 0 Answers

NavMesh agent moving to unassigned target 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges