{"id":13660874,"url":"https://github.com/jadvrodrigues/CustomNavMesh","last_synced_at":"2025-04-24T23:31:05.273Z","repository":{"id":42482666,"uuid":"306104411","full_name":"jadvrodrigues/CustomNavMesh","owner":"jadvrodrigues","description":"Alternative to Unity's NavMesh system where the agents avoid each other.","archived":false,"fork":false,"pushed_at":"2023-08-29T17:37:04.000Z","size":48604,"stargazers_count":207,"open_issues_count":0,"forks_count":25,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-10T15:44:40.413Z","etag":null,"topics":["agents","agents-avoid","avoidance","navmesh","navmeshagent","unity-navmesh"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jadvrodrigues.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-10-21T17:48:28.000Z","updated_at":"2024-11-08T03:22:41.000Z","dependencies_parsed_at":"2024-01-14T01:49:40.260Z","dependency_job_id":"efba03cf-d41d-4424-a5ce-17a74050041e","html_url":"https://github.com/jadvrodrigues/CustomNavMesh","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jadvrodrigues%2FCustomNavMesh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jadvrodrigues%2FCustomNavMesh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jadvrodrigues%2FCustomNavMesh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jadvrodrigues%2FCustomNavMesh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jadvrodrigues","download_url":"https://codeload.github.com/jadvrodrigues/CustomNavMesh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250727514,"owners_count":21477323,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agents","agents-avoid","avoidance","navmesh","navmeshagent","unity-navmesh"],"created_at":"2024-08-02T05:01:26.873Z","updated_at":"2025-04-24T23:31:00.263Z","avatar_url":"https://github.com/jadvrodrigues.png","language":"C#","readme":"# Custom Nav Mesh\n\nAlternative to Unity's NavMesh system where the **agents avoid the other non-moving agents** in their pathing. It uses the official navigation system, but you have to use its components instead. Compatible with **NavMeshComponents**.\n\n## How it works\n\n**How do the agents avoid others**? Unity's **NavMeshAgent** only goes around **NavMeshObstacles** and ignores the other agents in their path. By disabling **NavMeshAgent** and enabling **NavMeshObstacle** when an agent is not moving noticeably, the agents now avoid other non-moving agents in their pathing.\n\nUnity's NavMeshAgent             |  CustomNavMeshAgent\n:-------------------------:|:-------------------------:\n![](Assets/Examples/GIFs/1_before.gif)  |  ![](Assets/Examples/GIFs/1_after.gif)\n\n\u003e **1. Setting the destination** to the blue target's **exact** center position.\n\n**What if a moving agent collides against a stopped agent that's currently in obstacle mode**? By default, it wouldn't be able to push it. However, by:\n\n- duplicating the baked surface, obstacle, and agents;\n- making the duplicated agents switch between **NavMeshAgent** and **NavMeshObstacle** instead of the original ones;\n- having each original agent copy the duplicated one's velocity, and the duplicated one copy the original's position at every frame.\n\n![](Assets/Examples/GIFs/2_navigation_view.gif)\n\n\u003e **2.** The duplicated **NavMesh** components. The **hidden** components are on the **right** side.\n\n**You can** have agents **push** the **other agents**. For the **CustomNavMesh** system to work, you must use its **custom components**, which are **identical to the original ones**, making the transition seamless.\n\nNavMeshAgent vs NavMeshObstacle \"Agents\"            |  CustomNavMeshAgents\n:-------------------------:|:-------------------------:\n![](Assets/Examples/GIFs/3_before.gif)  |  ![](Assets/Examples/GIFs/3_after.gif)\n\n\u003e **3. Overlapping** agents by throwing one against the others. The **agents** are green and the **obstacles** blue.\n\n**Why not** just **switch** the agents back to **NavMeshAgent** instead? That wouldn't work because switching from **NavMeshObstacle** to **NavMeshAgent** isn't instant — it would take at least two frames.\n\n**What are the disadvantages?** Every **NavMesh** component is duplicated, which makes it less performant. However, it shouldn't be noticeable in most situations.\n\n## Custom classes\n\n**CustomNavMesh** – you can choose the hidden game objects **relative position** and whether or not they are **rendered** by accessing the class or through its **singleton** present in the **scene**.\n\n![](Assets/Examples/GIFs/4_custom_nav_mesh_fields.gif)\n\n\u003e **4.** Changing **CustomNavMesh** fields.\n\n- **CustomNavMeshSurface** – add to each surface that is going to be baked. These **surfaces** need to be **rendered meshes**. Both **Physics Colliders** and **Terrains** are ignored by it;\n- **CustomNavMeshObstacle** – replacement for **NavMeshObstacle**;\n- **CustomNavMeshAgent** – replacement for **NavMeshAgent**. The main extra properties are:\n  - **Block after Duration** – should the hidden agent start blocking (switch from agent to obstacle) if it hasn't surpassed a certain speed for a given time?\n  - **Unblock after Duration** - should the hidden agent periodically try to find a new shorter path and unblock (switch from obstacle to agent) when it finds one?\n  - **Unblock at Speed** - should the hidden agent unblock if it surpasses a certain speed?\n\n## How To Get Started\n\n**Clone or download** this repository and open the project in Unity. Alternatively, you can **copy the contents** of `Assets/CustomNavMesh` to an **existing project**.\n\nThe **scenes** used for the **GIFs** are available in the `Assets/Examples` folder. Just hit the **Space Bar** in play mode to test it.\n\nNote: This project is using the **Unity 2022.3 LTS** version. Tested in **PC Standalone**, **Android**, and **WebGL**.\n\n## Final thoughts\n\nThings that I might implement later:\n- Every time an agent in block mode does a refresh (tries to see if it should unblock), **SamplePosition** and **CalculatePath** are called. Both of these functions are **synchronous** and run on the **main thread**. I could implement the new experimental **NavMeshQuery operations** (not yet fully complete) which can be executed using the new **job system**.\n- Import more methods and properties from the original **NavMesh** components.\n- Create custom versions of the **NavMeshComponents'** components.\n\nIf you **need help** adding this to your project or have any **questions**, just [message me](https://forum.unity.com/members/jadvrodrigues.4503760/) and I'll try to help. I'm also interested in any **tips** or **suggestions** you may have, cheers!\n\n\n\n","funding_links":[],"categories":["GamePlay","C\\#","Open Source Repositories"],"sub_categories":["HUD","AI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjadvrodrigues%2FCustomNavMesh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjadvrodrigues%2FCustomNavMesh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjadvrodrigues%2FCustomNavMesh/lists"}