Baking 2D and 3D navigation
Build polygons from source geometry and verify a route.
Baking converts selected source geometry into traversable polygons: NavigationPolygon in 2D and NavigationMesh in 3D. Pathfinding uses that output, rather than automatically considering every visual model and collider in the level.
Three separate stages
- Prepare source geometry by parsing intended Entities or filling a source-data resource programmatically.
- Bake and check that the output contains polygons.
- Assign it to a region on the intended map, wait for publication and test a route.
Successful script compilation does not establish stages two or three. An empty NavigationMesh resource is not a usable route either.
Executed 2D and 3D example
Save NavigationBakeSamples.cs in a Reckfell 1.0.0 C# project:
using Reckfell;
using System;
public static class NavigationBakeSamples
{
public static NavigationPolygon BakeSquare2D()
{
using var source = new NavigationMeshSourceGeometryData2D();
source.AddTraversableOutline(new[]
{
new Vector2(0, 0), new Vector2(20, 0),
new Vector2(20, 20), new Vector2(0, 20)
});
var polygon = new NavigationPolygon { AgentRadius = 1, CellSize = 1 };
NavigationServer2D.BakeFromSourceGeometryData(polygon, source);
if (polygon.GetPolygonCount() > 0) return polygon;
polygon.Dispose();
throw new InvalidOperationException("2D bake produced no polygons.");
}
public static NavigationMesh BakeFloor3D()
{
using var source = new NavigationMeshSourceGeometryData3D();
source.AddFaces(new[]
{
new Vector3(-10, 0, -10), new Vector3(10, 0, 10), new Vector3(-10, 0, 10),
new Vector3(-10, 0, -10), new Vector3(10, 0, -10), new Vector3(10, 0, 10)
}, Transform3D.Identity);
var mesh = new NavigationMesh
{
AgentRadius = 0.5f, AgentHeight = 2,
CellSize = 0.25f, CellHeight = 0.25f
};
NavigationServer3D.BakeFromSourceGeometryData(mesh, source);
if (mesh.GetPolygonCount() > 0) return mesh;
mesh.Dispose();
throw new InvalidOperationException("3D bake produced no polygons.");
}
}BakeSquare2D() synchronously bakes a 20×20 square using agent radius 1. The check produced polygons within approximately 1–19 on both axes; assigning them to a region produced a path from (2, 2) to (18, 18).
BakeFloor3D() synchronously bakes a flat floor from two triangles. The executed output contains polygons and supports a server route across the floor. Triangle vertex order matters: incorrect orientation can make a surface unwalkable. Do not reorder this example arbitrarily.
The caller owns the returned resource. Use it in a region and dispose of its reference when no longer needed. The helper disposes source-data resources itself. This example does not create a visual model, collider or character.
Parameters controlling traversability
| Parameter | Consideration |
|---|---|
AgentRadius | Clearance for the character center near boundaries. Changing NavigationAgent radius does not rebake a mesh for another body size. |
3D AgentHeight | Required free-space height during baking. Does not replace the character physics shape. |
CellSize, CellHeight | Build resolution. Rasterization can shift final boundaries and surface height. |
When assigning the 3D output, align map MapSetCellSize and MapSetCellHeight with the resource. The check uses mesh.CellSize and mesh.CellHeight. Do not require path height to exactly match source y=0: the path is projected onto the built surface.
An excessive radius can remove narrow passages. An insufficient radius can allow paths the physics body cannot fit through. Polygon count alone does not establish clearance for a real character.
Parse a level through NavigationRegion
A region Entity combines source parsing, baking and submission. Resource options select visual/physics geometry, collision layers and groups. If a wall is not selected for parsing, the bake does not know about it.
Parse EntityTree on the main thread. Large projects can prepare data separately and use asynchronous baking, but returning from a call does not establish completed output: wait for completion and map publication. This helper uses only synchronous source-data APIs; editor operations and asynchronous baking were not tested here.
Diagnose empty or incorrect output
- No polygons: check selected geometry, triangle orientation, dimensions, radius and bake restrictions.
- Polygons exist but no path does: check region, map, layers and synchronization.
- A path crosses a wall: check whether the wall entered the source data, then rebake.
- Resources fail to connect: inspect edge connections, rather than only the visual model.
Executed checks cover the exact code, synchronous 2D/3D baking, boundary insets and queries using both outputs. Real-level parsing, obstacles/low ceilings, physics bodies, editor UI, asynchronous execution, export and performance were not tested by this suite.