Search Unity

[Workaround] Changing Unity Editor "Baked Agent Size" settings from script?

Discussion in 'Navigation' started by OneManBandGames, Oct 3, 2017.

  1. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    207
    Hi all,

    I'm currently working on a project that utilizes an "automatic terrain build pipeline". This means that when I'm done with placing stuff like buildings on my terrain, I start a script that will take care of generating trees, details and textures on the terrain, build a navmesh and split the terrain up in streamable chunks for world loading etc. etc.

    I wanted to increase the default "Baked Agent Size" agent radius for the navmesh creation a bit, which made me run into the following problem:

    I currently use NavMeshBuilder.BuildNavMesh() in the build pipeline to bake the navmesh in the scenes. This equals pressing the "Bake" button in the Unity Navigation window, which means the baked navmesh will be saved with the scene. During runtime the navmesh will automatically be loaded & available for navmesh agents when the scene is loaded.

    However in my build pipeline a NEW scene gets created for the generation, which means the agent radius will always default back to 0.5 before I call NavMeshBuilder.BuildNavMesh(). I did not find any way to change this default setting from my build pipeline script.

    I experimented with using custom NavmeshBuildSettings and NavMeshBuilder.BuildNavMeshData(). This will create a navmesh with the increased agent size as I want it, but this navmesh then will never be stored with the scene.

    Is there a way how I can either change the default navmesh agent size in the editor navigation window from a script, or store the navmesh I create with BuildNavMeshData() in the scene it was built upon?

    I'm aware of the Navmesh component workflow, however this does not seem to solve my problem as from how I understand the documentation this would create navmeshes which would not be stored with the scene as well.
     
  2. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    207
    Update: After re-reading the documentation for the Navmesh component workflow it turns out that you can very well create navmeshes that will be baked & saved with the scene just as with the regular editor navigation window. I think I must have misread some other part of the documentation which lead me to the misconception that the components would be for runtime navmesh creation only.
    This means I can use the Navmesh component workflow as a workaround to get my different agent size running in my terrain build pipeline.
     
  3. BisschenHeller

    BisschenHeller

    Joined:
    Dec 20, 2019
    Posts:
    2
    Yo I know this is three years old but I'm having the same issue now, what exactly was your workaround? Did you actually manage to change the radius during runtime?
     
    iivanovazur likes this.
  4. BisschenHeller

    BisschenHeller

    Joined:
    Dec 20, 2019
    Posts:
    2
     
    iivanovazur likes this.