# Navigation AI NavMesh Issue

**URL:** https://community.cesium.com/t/navigation-ai-navmesh-issue/27107
**Category:** Cesium for Unity
**Created:** [October 2, 2023, 9:21pm UTC](https://community.cesium.com/t/navigation-ai-navmesh-issue/27107 "2023-10-02T21:21:01Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![BlueMoose](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/bluemoose/32/20372_2.png) [@BlueMoose](https://community.cesium.com/u/BlueMoose)
#### Post date: [October 2, 2023, 9:21pm UTC](https://community.cesium.com/t/navigation-ai-navmesh-issue/27107/1 "2023-10-02T21:21:02Z")

</div>

I am trying to use Unity’s navigation AI capabilities, but am unable to generate a NavMesh using Cesium. It complains that there are more than 100,000 meshes in the scene. I am assuming it is because of all the loaded tiles. Is there a way around this or to limit the amount of meshes Cesium generates in Unity?

---

<div class="post-metadata">

### Author: ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)
#### Post date: [October 4, 2023, 12:47am UTC](https://community.cesium.com/t/navigation-ai-navmesh-issue/27107/2 "2023-10-04T00:47:30Z")

</div>

I don’t know why there would be 100,000 meshes in the scene. Even a very detailed scene should have on the order of a thousand meshes, not a hundred thousand. Can you please provide us with detailed instructions to reproduce the problem you’re seeing, preferably starting with the Cesium for Unity Samples project?

---

<div class="post-metadata">

### Author: ![BlueMoose](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/bluemoose/32/20372_2.png) [@BlueMoose](https://community.cesium.com/u/BlueMoose)
#### Post date: [October 4, 2023, 4:00am UTC](https://community.cesium.com/t/navigation-ai-navmesh-issue/27107/3 "2023-10-04T04:00:15Z")

</div>

I followed the steps found in the Quickstart here: [Cesium for Unity Quickstart – Cesium](https://cesium.com/learn/unity/unity-quickstart/)

After having the scene setup I tried to use the AI.Navigation package and use the NavMesh in my scene. When I go to bake in the NavMesh Agent menu it throws the error complaining about there being more than 100,000 meshes.

---

<div class="post-metadata">

### Author: ![joseph.kaile](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/joseph.kaile/32/3476_2.png) [@joseph.kaile](https://community.cesium.com/u/joseph.kaile)
#### Post date: [October 4, 2023, 5:04am UTC](https://community.cesium.com/t/navigation-ai-navmesh-issue/27107/4 "2023-10-04T05:04:39Z")

</div>

> [@BlueMoose](#):
>
> 0 meshes in the scene. I am assuming it is because of all the loaded tiles. Is there a way around this or to limit the amount of meshes Cesium generates in Unity?

Hello,

Is the error the same as this one?  
RuntimeNavMeshBuilder: Ignoring source mesh because it is too large. Each mesh dimension must not exceed 100000 units.

If you’re using a NavMeshSurface, there’s a way to limit the extents of the NavMesh with a Volume (i.e. a box collider).

---

<div class="post-metadata">

### Author: ![BlueMoose](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/bluemoose/32/20372_2.png) [@BlueMoose](https://community.cesium.com/u/BlueMoose)
#### Post date: [October 4, 2023, 10:41am UTC](https://community.cesium.com/t/navigation-ai-navmesh-issue/27107/5 "2023-10-04T10:41:16Z")

</div>

Yes that is the error. How do you limit using a volume??

---

<div class="post-metadata">

### Author: ![ihsan\_tokel](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ihsan_tokel/32/14376_2.png) [@ihsan\_tokel](https://community.cesium.com/u/ihsan_tokel)
#### Post date: [October 13, 2023, 2:06am UTC](https://community.cesium.com/t/navigation-ai-navmesh-issue/27107/6 "2023-10-13T02:06:18Z")

</div>

Same here. I am using Cesium for Unity to model a specific part of the world; however once I try to put some characters and adding state machine behaviors to make them move inside the map, I have to bake the map. But adding NavMeshSurface component to Cesium3DTileset does not work (“Updating the NavMesh failed due to an excessive number of tiles”)  
I think once I click bake, it tries to bake whole world! That might be the reason it throws “exceeding 100000 units”  
Is there any way to limit the number of tiles to be baked? I tried to add some planes and add NavMeshSurface component to these planes and bake only them, but did not work.

---

<div class="post-metadata">

### Author: ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)
#### Post date: [October 13, 2023, 3:28am UTC](https://community.cesium.com/t/navigation-ai-navmesh-issue/27107/7 "2023-10-13T03:28:45Z")

</div>

I don’t know a lot about NavMeshes in Unity, but I think the “100000 units” isn’t referring to the number of tiles / meshes. It’s referring to the coordinate values of a single object covering more than 100,000 meters.

It sounds like it’s just a warning, though, and that it will simply ignore those big tiles. That’s probably fine, because only the large, distance, low-detail tiles will cover more than 100k meters. And if you’re working in a small area, you probably don’t care much about those.

But fundamentally, this idea of “baking” the navigation is flawed. The set of tiles can and will (and must!) change at runtime. Baking at Editor time is simply not a viable solution in the general case. If that’s the only option Unity provides, then this is a Unity limitation that prevents the use of its navigation system with something like 3D Tiles. Maybe in very limited use-cases you can get Cesium for Unity to load just the tiles you want, bake the navigation based on that, and it will be “good enough” even as the view-dependent level-of-detail changes. It’s going to be super error-prone, though. You might be better off manually constructing meshes to guide your navigation rather than trying to use the 3D Tiles directly.

---

<div class="post-metadata">

### Author: ![ihsan\_tokel](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ihsan_tokel/32/14376_2.png) [@ihsan\_tokel](https://community.cesium.com/u/ihsan_tokel)
#### Post date: [October 13, 2023, 12:35pm UTC](https://community.cesium.com/t/navigation-ai-navmesh-issue/27107/8 "2023-10-13T12:35:07Z")

</div>

Thanks for your reply Kevin. One of the reasons I am trying to do it using Cesium for Unity is reproducibility: so manually constructing meshes won’t work with one of my primary objectives.  
But, each time I am planning to use a specific part of the world as a use case in my project. So if there is a way to limit Cesium for Unity to load only the tiles I want it could work (actually, I was expecting to do it using subscenes feature but it seems like it is not designed for that purpose).

---

<div class="post-metadata">

### Author: ![janine](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/janine/32/5135_2.png) [@janine](https://community.cesium.com/u/janine)
#### Post date: [October 16, 2023, 1:44pm UTC](https://community.cesium.com/t/navigation-ai-navmesh-issue/27107/9 "2023-10-16T13:44:37Z")

</div>

I haven’t prototyped this myself, but you could try using the `OnTileGameObjectCreated` event on the `Cesium3DTileset`, and only applying the NavMeshSurface component if the tile’s bounds are within a certain area.

---

<div class="post-metadata">

### Author: ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)
#### Post date: [October 16, 2023, 10:23pm UTC](https://community.cesium.com/t/navigation-ai-navmesh-issue/27107/10 "2023-10-16T22:23:44Z")

</div>

> [@ihsan\_tokel](#):
>
> So if there is a way to limit Cesium for Unity to load only the tiles I want it could work

You can do this with a tile excluder:

> <https://github.com/CesiumGS/cesium-unity/pull/248>
>
> Depends on CesiumGS/cesium-native#608
> 
> Added \`CesiumTileExcluder\`, which is a …C# version of cesium-native's \`ITileExcluder\`.
> 
> The idea is that we can add a C# class like this to our project:
> 
> \`\`\`csharp
> using CesiumForUnity;
> using UnityEngine;
> 
> \[RequireComponent(typeof(BoxCollider))\]
> public class CesiumBoxExcluder : CesiumTileExcluder
> {
> private BoxCollider \_boxCollider;
> private Bounds \_bounds;
> 
> public bool invert = false;
> 
> protected override void OnEnable()
> {
> this.\_boxCollider = this.gameObject.GetComponent\<BoxCollider\>();
> this.\_bounds = new Bounds(this.\_boxCollider.center, this.\_boxCollider.size);
> 
> base.OnEnable();
> }
> 
> protected void Update()
> {
> this.\_bounds.center = this.\_boxCollider.center;
> this.\_bounds.size = this.\_boxCollider.size;
> }
> 
> public bool CompletelyContains(Bounds bounds)
> {
> return Vector3.Min(this.\_bounds.max, bounds.max) == bounds.max &&
> Vector3.Max(this.\_bounds.min, bounds.min) == bounds.min;
> }
> 
> public override bool ShouldExclude(Cesium3DTile tile)
> {
> if (!this.enabled)
> {
> return false;
> }
> 
> if (this.invert)
> {
> return this.CompletelyContains(tile.bounds);
> }
> 
> return !this.\_bounds.Intersects(tile.bounds);
> }
> }
> \`\`\`
> 
> And then add an instance of this class as a component on the \`Cesium3DTileset\` or any of its parents, up to and including the \`CesiumGeoreference\`.
> 
> With that in place, cesium-native will call the \`ShouldExclude\` method for each tile that it is considering loading or rendering. This will happen a \_lot\_, so this method needs to be fast. Return true to skip loading and rendering that tile. Return false to load it and render it as normal.
> 
> In the implementation above, a user-defined BoxCollider is also attached to the same GameObject as the CesiumBoxExcluder. Any tiles that intersect this BoxCollider are loaded and rendered, others are not. So tiles that are entirely outside of the box are ignored. The given tile's \`bounds\` property is an axis-aligned bounding box in the same coordinate system as the \`CesiumBoxExcluder\`, so it's easy to do tests like this.
> 
> In this screenshot, the BoxCollider is the green box in the middle of Melbourne. All of the visible tiles are at least partially inside the box:
> 
> !\[image\](https://user-images.githubusercontent.com/924374/225528568-647a9bb8-58c1-4635-b0dc-c24713b7ff95.png)
> 
> If we disable the CesiumBoxExcluder, all the tiles load as normal:
> 
> !\[image\](https://user-images.githubusercontent.com/924374/225528858-5986386f-7413-434f-8050-37d5ff1bc61c.png)
> 
> Also in this PR: Extended Reinterop to allow constructors of blittable value types to be called from C++. On the C++ side, these are exposed as \`Constrct\` methods rather than C++ constructors so that brace initialization can continue to be used to initialize fields without calling into C#.

Janine’s suggestion is good as well. That way you can avoid doing navigation on large meshes even when they happen to be visible.
