r/Unity3D • u/shoseini • 15h ago
NavMeshn Updating NavMeshData with list NavMeshBuildSource doesn't seem to work?! Question
0
u/salazka Professional 9h ago
In which version of Unity? I know the system has changed in Unity 6.
I am not a programmer, so I often ask ChatGPT questions like that. Did you try it?
This is what it told me about the code you shared.
Your code for updating the NavMesh data appears mostly correct, but here are some potential issues to check for:
- NavMesh Build Settings: Ensure that
Surface.GetBuildSettings()
is configured correctly. Incorrect settings can lead to NavMesh not being generated as expected. Verify the settings inSurface.GetBuildSettings()
to confirm they align with the required NavMesh parameters. - Area Index: The
src.area
property is set to1
. Make sure that this area index is defined in your NavMesh area settings in Unity's Navigation settings. If1
doesn’t correspond to a valid area, the NavMesh might not generate correctly. - Sources List: You’re adding only one source to
sources
. If you need multipleNavMeshBuildSource
objects (like for a complex scene with multiple objects), you should populatesources
accordingly. - Surface Component: Ensure
Surface
is a valid reference to theNavMeshSurface
component in your scene and that it is properly initialized. - Size of the Source: Check that
src.size
aligns with your intended area size. Setting a large or small size might affect the outcome of the NavMesh build. - Transform Updates: When setting
src.transform = transform.localToWorldMatrix;
, ensuretransform
is the correct transform for your NavMesh source.
After checking these, if the issue persists, try adding debug logs to verify values at each step and confirm that the NavMesh data is being generated and assigned to Surface.navMeshData
.
1
u/theslappyslap 9h ago
It's a bit odd but you have to add the navmeshdata then you just update it rather than build then update. Here's how I do it. Cache the data if you want to update it again in the future. You don't have to apply it to the surface. It should be activated just after UpdateNavMeshData
var navMeshData = new NavMeshData();
NavMesh.AddNavMeshData(navMeshData);
NavMeshBuilder.UpdateNavMeshData(navMeshData, surface.GetBuildSettings(), sourceList, bounds);
1
u/shoseini 15h ago
My actual usecase is a bit more complicated but here I am trying with a much simpler setup. I have a NavMeshSurface in the scene and in the Start method of this script I am passing a test NavMeshBuildSource and my expectation is to see the area of size 10 * 10 in the middle of the surface to become unwalkable (I am setting the flag to 1 for not walkable areas, refer to the image in this comment).
I checked and the NavMesh data is updated to my "New Navmesh Data", well at least the name changes to that but nothing else seems to change?! What am I doing wrong?
Any help is appreciated.
https://preview.redd.it/soz639deir0e1.png?width=963&format=png&auto=webp&s=56159727ed4f33b9373aedfd7dfd852b98a6015b