KROYSDOCS
HomeWhat's newv0.1.0
MANUAL / Editor / Navigation and streaming

Navigation and streaming

Bake a navmesh so characters and server bots find paths through the level, and split large worlds into chunks that load by distance.

PanelsNavigation, World Streaming
ScriptingNavigation, NavAgent classes
01

Bake a navmesh

Add a NavMesh Surface component to the level, open the Navigation panel (Level workspace) and press Bake. The settings describe the agents that walk it: Agent Radius, Agent Height, Max Slope and Max Step Height, plus the Cell Size of the voxel grid and a layer filter for the geometry to include. Baking runs in the background and can be cancelled. Show Navigation Overlay draws the result in the Viewport.

The navmesh is saved as an asset and ships with the game and with the dedicated server.

02

Paths in scripts

A NavMesh Agent component walks an entity to a destination: NavAgent.SetDestination(entity, point). For your own movement, ask for the path and follow its corners:

Navigation.IsReady is false until the scene has a baked navmesh; without one, FindPath fails and code should fall back to moving straight. See Navigation.

ChaseBots.cs
public sealed class ChaseBots : GameMode
{
    private readonly List<Vector3> path = new();

    protected override void OnStart()
    {
        GameSession.AddBot("Hunter");
    }

    protected override void OnFixedUpdate(float fixedDeltaTime)
    {
        Player? target = GameSession.Players.FirstOrDefault(p => !p.IsBot);
        foreach (Player bot in GameSession.Players.Where(p => p.IsBot))
        {
            if (target is not Player human)
            {
                Bot.Stop(bot);
                continue;
            }
            Vector3 from = bot.Entity.Transform.WorldPosition;
            Vector3 to = human.Entity.Transform.WorldPosition;
            // With a baked navmesh, walk the path's corners; without one, head straight there.
            Vector3 next = to;
            if (Navigation.IsReady && Navigation.FindPath(from, to, path) != NavPathStatus.Failed && path.Count > 1)
                next = path[1];
            Bot.MoveToward(bot, next, arriveDistance: 1.0f, sprint: Vector3.Distance(from, to) > 8.0f);
        }
    }
}
03

World streaming

Large worlds are split into cells that load and unload around the player, with their colliders, navmesh tiles and terrain, within a time and memory budget: see World streaming. A streamed level's navmesh is split into its cells, so bake it before partitioning the level.

Older levels may use World Chunk components instead: a chunk's entities stay in the scene and are only hidden and paused by distance. The World Streaming panel lists them under World Chunks (Legacy).

KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.