Skip to content

Generating navigation mesh

in0finite edited this page May 8, 2022 · 1 revision

Navigation mesh is what AI (NPC) uses to find paths and navigate around. It has to be generated manually, because it's not present in original game.

To generate navigation mesh, you can use tools in Editor menu: SanAndreasUnity -> Nav mesh generator. You would first need to load game data, import entire world into Unity, and generate water collision.

Fortunately, you don't have to do all of this, because there is a script which supports generating navigation mesh from command line. The script performs all tasks mentioned above, saves navigation mesh as an asset inside project folder, and exits Unity. Here is how to use it:

path/to/Unity/executable -logFile - -batchmode -nographics -projectPath path/to/project -executeMethod SanAndreasUnity.Editor.NavMeshGeneratorCommandLine.Run -navMeshGenerationMaxJobWorkers:4

-navMeshGenerationMaxJobWorkers specifies the number of threads to use. You can assign 0 to use all threads. Default value is 2.

Generated navigation mesh will be saved at Assets/GeneratedNavMeshFromCommandLine.asset.

Note that generation of navigation mesh is CPU-heavy task and can take a while. For example, on a dual-core cloud server, it takes around 50 minutes.

Clone this wiki locally