### building navmesh at runtime and using it for spawned aiplayers

There are no stupid questions, just stupid answers.

#### building navmesh at runtime and using it for spawned aiplayers

slapin
Posts: 21
Joined: Thu Aug 10, 2017 12:56 am
Hi all!

I was looking very hard for how to instantiate navmesh at run time and save it into save game for later use and could not find anything.
Is there some example?
Also I tried to use pre-made navmesh with spawned aiplayer but could not find any example on how to do that and what I miss.
I probably don't know enough to search properly so could you please help and provide some info (best for post 3.7 or latest version).

Thanks!

#### Re: building navmesh at runtime and using it for spawned aiplayers

Duion
Posts: 805
Joined: Sun Feb 08, 2015 1:51 am

You could trigger to regenerate the navmesh while the game is running, you can regenerate small parts like one cell to save performance.

#### Re: building navmesh at runtime and using it for spawned aiplayers

slapin
Posts: 21
Joined: Thu Aug 10, 2017 12:56 am
I'd kill for an example though.

My map is randomly generated at start, so I need to have navmesh generated at start,
then small portions can be generated.

But I wonder how to use the result mesh.

i.e. if I use from script

$navmesh = new NavMesh() { position = "0 0 0"; scale = "512 512 10"; };$navmesh.build();

what comes next?

#### Re: building navmesh at runtime and using it for spawned aiplayers

Duion
Posts: 805
Joined: Sun Feb 08, 2015 1:51 am

Try out the functions in the world editor on the navmesh, there is an option to select single tiles and regenerate them.
But in your case it is probably enough to generate the navmesh once as a whole at start, it will add quite some loading time though, since navmesh generation takes a while.
You need to try it in editor first manually to find good settings.

#### Re: building navmesh at runtime and using it for spawned aiplayers

Azaezel
Posts: 383
Joined: Tue Feb 03, 2015 9:50 pm

Old create on the fly code is old, but should by and large still be accurate

Code: Select all

{
%newMesh = new NavMesh(theNavMesh)
{
saveIntermediates = "0";
build = "0";
fileName = "levels/temp/nav.nm"; //<--------------------- file save loc
borderSize = "1";
cellSize = "0.3";
cellHeight = "0.25";
actorHeight = "2";
actorClimb = "0.25";
walkableSlope = "45";
detailSampleDist = "6";
detailSampleError = "1";
maxEdgeLen = "12";
simplificationError = "1.3";
minRegionArea = "8";
mergeRegionArea = "20";
tileSize = "32";
renderMode = "Navmesh";
renderInput = "0";
renderConnections = "0";
position = "0 0 3.5";
rotation = "1 0 0 0";
scale = "30 30 10"; //<--------------------- dimensions
canSave = "1";
canSaveDynamicFields = "1";
alwaysRender = "0";
cornerAngle = "30";
createCoverPoints = "0";
renderContours = "0";
renderGeometry = "0";
renderNavmesh = "1";
renderSegments = "1";
};