0
\$\begingroup\$

My code generates a level by looping through a list of empty game objects and choosing a random object from another list of objects, then instantiating that object at the empty object's position. Then I call BuildNavMesh on my navmesh surface and it gives me this error:

RuntimeNavMeshBuilder: Source mesh Buildings does not allow read access. This will work in playmode in the editor but not in player

  • UnityEngine.AI.NavMeshBuilder:BuildNavMeshData (UnityEngine.AI.NavMeshBuildSettings,System.Collections.Generic.List`1<UnityEngine.AI.NavMeshBuildSource>,UnityEngine.Bounds,UnityEngine.Vector3,UnityEngine.Quaternion)
  • Unity.AI.Navigation.NavMeshSurface:BuildNavMesh () (at Library/PackageCache/[email protected]/Runtime/NavMeshSurface.cs:251)
  • CityGenerator:Start () (at Assets/CityGenerator.cs:19)

This is the code:

public List<GameObject> cityChunks;
int cityChunk;
public List<GameObject> grid;
public NavMeshSurface surface;
void Start()
{
    foreach (GameObject empty in grid)
    {
        cityChunk = Random.Range(0, cityChunks.Count);
        Instantiate(cityChunks[cityChunk], empty.transform.position, Quaternion.identity);
    }
    surface.BuildNavMesh();
}
\$\endgroup\$
2
  • \$\begingroup\$ Did you enable read access on the meshes that you spawn dynamically this way? \$\endgroup\$
    – DMGregory
    Commented Oct 24, 2022 at 12:47
  • \$\begingroup\$ No, How can I do that? \$\endgroup\$ Commented Oct 24, 2022 at 12:52

1 Answer 1

1
\$\begingroup\$

This error message is telling you exactly what is wrong: the model you're trying to build a navmesh for has not been marked as readable, so in a built game the CPU will not be able to read its geometry information to build that navmesh.

So: select the models you want to spawn dynamically this way, and tick the "Read/Write Enabled" box in their import settings:

Model import settings inspector - Model tab

This is covered in the documentation:

Read/Write Enabled When you enable this option, Unity uploads the Mesh data to GPU-addressable memory, but also keeps it in CPU-addressable memory. This means that Unity can access the Mesh data at run time, and you can access it from your scripts. For example, you might want to do this if you’re generating a Mesh procedurally, or if you want to copy some data from a Mesh.

When this option is disabled, Unity uploads the Mesh data to GPU-addressable memory, and then removes it from CPU-addressable memory.

By default, this option is disabled. In most cases, to save runtime memory usage, leave this option disabled. For information on when to enable Read/Write Enabled, see Mesh.isReadable.

That last link there says:

You should only enable it under the following circumstances:
...

  • When you use the Mesh to bake a NavMesh using the NavMesh building components at run time.

Just typing "unity mesh read access" into a search engine turns up a link to this documentation as one of the top results, as well as several past troubleshooting threads explaining how to resolve your error. So please get in the habit of looking at the key words in your error message and searching for them, rather than jumping to the conclusion that the error is just "weird" and posting a new question about it. You'll find your answers faster by doing this basic level of research first.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .