- Home /
Where is 'min region area' setting when baking navmesh at runtime?
When using NavMesh static baking, I got the results I wanted, only when I set "Min Region Area" in the Bake tab of the Navigation window, to 0.05.
I can't find how to control that setting when I bake my NavMesh at run time (Unity 5.6) through the NavMeshBuilder class - as a result, my NavNesh is broken.
Can someone point me to how I control this setting or equivalent, at runtime?
Answer by MeTheFlea · Apr 21, 2017 at 09:18 AM
Hey, I was looking for something similar and could not find a public API for it. However, if you examine the decompiled UnityEngine.dll you can see that there is a private float m_MinRegionArea;
which means that we can set that value using reflection.
Note that there is no guarantee that this will keep working in later versions of Unity, but for now (Unity 5.6.0f3) this is working for me:
NavMeshBuildSettings settings = NavMesh.GetSettingsByIndex( 0 ); // or whatever
var prop = typeof( NavMeshBuildSettings ).GetField( "m_MinRegionArea", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance );
object boxedSettings = settings;
prop.SetValue( boxedSettings, [YOUR_VALUE] );
settings = (NavMeshBuildSettings)boxedSettings;
Take a look at this stack overflow question if you are wondering why it's required to do object boxedSettings = settings;
Hello, I am trying to change the "m_VoxelSize"
and for that, I know I need to change "m_OverrideVoxelSize"
to true. However, I don't know how to do that. I used your method to change "m_VoxelSize"
. However, nothing happened when I run in Unity. I know something must happen if I change the voxelSize to 0.5f because when I did manually it acts as I desire but because I am procedurally generating my world I need it to procedurally generate the Nav$$anonymous$$esh with a specific voxelSize I want it to be. However, it's my second day on the internet but I couldn't find an explanation for how to change the voxel size through the script on the new version of the Unity (2019.3.10f1). Normally people. get around this by creating prefabs with premade Nav$$anonymous$$esh on them, however, in my case, this is not an option since I am generating a voxel terrain made out of (1,1,1) scale cubes. Hence I need to find a way to change the voxelSize Somehow.
I would really appreciate if you can find a solution.
void UpdateNav$$anonymous$$esh(bool asyncUpdate = false)
{
Nav$$anonymous$$eshSourceTag.Collect(ref m_Sources);
var defaultBuildSettings = Nav$$anonymous$$esh.GetSettingsByID(0);
var vox = typeof( Nav$$anonymous$$eshBuildSettings ).GetField("m_OverrideVoxelSize");
var prop = typeof( Nav$$anonymous$$eshBuildSettings ).GetField( "m_VoxelSize", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance );
object boxedSettings = defaultBuildSettings;
vox.SetValue(boxedSettings, true);
prop.SetValue(boxedSettings, 0.5f);
defaultBuildSettings = (Nav$$anonymous$$eshBuildSettings)boxedSettings;
var bounds = QuantizedBounds();
if (asyncUpdate)
m_Operation = Nav$$anonymous$$eshBuilder.UpdateNav$$anonymous$$eshDataAsync(m_Nav$$anonymous$$esh, defaultBuildSettings, m_Sources, bounds);
else
Nav$$anonymous$$eshBuilder.UpdateNav$$anonymous$$eshData(m_Nav$$anonymous$$esh, defaultBuildSettings, m_Sources, bounds);
}
Above is the part I am trying to reach to the "m_VoxelSize" in UnityEngine.AI$$anonymous$$odule.dll I am using the LocalNav$$anonymous$$eshBuilder script from https://github.com/Unity-Technologies/Nav$$anonymous$$eshComponents. I just edited. a bit to also have a Nav$$anonymous$$esh with a specific VoxelSize. However, I got no success.
Thank you in advance!
Answer by Silverlode · Apr 14, 2017 at 05:47 AM
Well, I haven't found this setting yet, nor do I understand how that settings translates to the runtime system, but it appears it wasn't that setting that was my only issue - the objects used to create the navmesh were at an angle, but I didn't realized this with my orthogonal view. Correcting the angle gave me the navmesh I wanted - but I'm still curious how to control the threshold for region size to be culled?
Your answer
Follow this Question
Related Questions
Multiple Navmesh Bakes 2 Answers
Need help with navmesh,Already bake Navmesh but still got error 1 Answer
GameObject's Navigation Area from script 0 Answers
NavMesh baking 1 Answer
Bake navmesh after changing the size 0 Answers