• 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
Question by 2-Zons · Nov 24, 2015 at 10:38 PM · networkingnavmeshnavmeshagentnavigation

Off Mesh Link - Limiting access to certain agents

In my game I have dynamically created Nav Mesh agents that wander around the map. There are doors on the map which I am using Off Mesh Links for. Is there a way I could have these off mesh links only accessible to certain agents. Is this possible? Do I need to use an Obstacle?

Any help is greatly appreciated.

Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by CraigGraff · Nov 25, 2015 at 10:05 AM

@2-Zons You can just set the navigation area of the Off Mesh links to some custom navigation areas (added in the Areas tab of the Navigation panel). Then use something like the following code to set the area mask of each agent that is allowed to travel through a gate.

 using UnityEngine;
 
 public enum Gate {Red=3, Green, Blue}
 
 public class AgentAreaMaskExample : MonoBehaviour
 {
     NavMeshAgent agent;
     void setGateAllowed(Gate gate, bool allowed)
     {
         if (allowed)
             // set bit on
             agent.areaMask |= 1 << (int)gate;
         else
             // set bit off
             agent.areaMask &= ~(1 << (int)gate);
     }
 
     void Start()
     {
         agent = GetComponent<NavMeshAgent>();
         setGateAllowed(Gate.Green, true);
     }
 }
Comment

People who like this

0 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 2-Zons · Nov 25, 2015 at 03:30 PM 0
Share

Thank you for the reply. Can those areas be dynamically assigned at runtime? The doors I am using are placed by the player.

avatar image CraigGraff 2-Zons · Nov 25, 2015 at 04:34 PM 0
Share

@2-Zons Yes, with something like:

 OffMeshLink link = GetComponent<OffMeshLink>();
 
 link.area = 3; // set link to only allow characters if they can traverse area 3



avatar image 2-Zons · Nov 26, 2015 at 12:47 AM 0
Share

This looks like it will do the trick. As soon as I can get it implemented in my project and test it I will accept this answer as correct. There seem to be a lot of people following this question, so I don't want to accept the answer until I am certain it works as desired.

avatar image

Answer by 2-Zons · Nov 27, 2015 at 04:01 AM

This worked just as described. One thing that I needed to be careful with was the doors are prefab's and and the enter and exit tied to child game objects. The doors needed placed so that the enter and exit transforms are within a certain tolerance of the nav mesh surface. if placed too high they wont function properly. Thanks @CraigGraff

Comment

People who like this

0 Show 0 · 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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

44 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

Related Questions

Navmesh has some problems? 0 Answers

How to exclude certain navmesh obstacles on runtime? 2 Answers

NavMesh pathing not working 0 Answers

Have players NavMeshAgent ignore Enemy NavMeshObstacle carving 0 Answers

Networked movement using navmesh agent 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