How to specify settings for the NavMeshBuilder class?


I am currently working with the NavMesh features provided in Unity 3.5 and I have a small doubt. I would like to create a NavMesh and assign user defined layers for certain objects in my scene. I want to crate a script performing the aforementioned actions. I looked at the documentation where I found the NavMeshBuilder class which contains a method called Build which builds a NavMesh. I would like to know if this method can be used for my purpose. Also the class contains a navMeshSettingsObject variable. Can I use this for specifying layer settings? It would be great if someone would help me with this .


Well, with the NavMeshBuilder.navMeshSettingsObject you can only assign settings concerning to bake. (see: Window/Navigation > Bake)

The way to alter it, is by using the SerializedObject and SerializedProperty classes.


SerializedObject settingsObject = new SerializedObject(NavMeshBuilder.navMeshSettingsObject);
SerializedProperty agentRadius = settingsObject.FindProperty("m_BuildSettings.agentRadius");
agentRadius.floatValue = 5f;

Here’s a list of avaiable float properties:

  • m_BuildSettings.agentRadius
  • m_BuildSettings.agentHeight
  • m_BuildSettings.agentSlope
  • m_BuildSettings.ledgeDropHeight
  • m_BuildSettings.agentClimb
  • m_BuildSettings.maxJumpAcrossDistance
  • m_BuildSettings.minRegionArea
  • m_BuildSettings.widthInaccuracy
  • m_BuildSettings.heightInaccuracy

and a bool property

  • m_BuildSettings.accuratePlacement

If you want to change navigation layers see the GameObjectUtility class.