Skip to content

Minimal Sample

Overview

Path: Samples/Scenes/minimal_example.unity

This contains a small 2D grid and pathfinding agent used in the Quickstart. The following can be done in-editor or in playmode.

  1. On the PathfindingGrid object, click "Build" to generate the collision matrix.
  2. On the Pawn object click "Generate Path"

Scene

Structure

World

This contains the collision cells / tiles of the grid that act as obstacles. Each has a Box Collider 2D with it's layer set to Default. Move these around to creature a simple 2D obstacle "world" for the agent.

Snapping

Each is 1x1 unit tile, because the cell size on the PathfindingGrid object is set to 1 world unit. Make sure to turn on grid snapping in the scene to more easily move around the tiles.

This is also helpful for centering the grid itself and the camera.

GridSettings


Pawn

This is our pathfinding "agent". The important Component here is the DemoPathingAgent that has some helpers to get you started using the package. Since we're not using dynamic obstacles here, the layer is set to Ignore Layout.

Target

A Transform used to represent the path target with the agent's position as the start. Like the agent, the layer is set to Ignore Layout.

PathfindingGrid

Finally the PathfindingGrid object acts as a MonoBehaviour helper to store static and dynamic collision matrices in a grid. This is done through the PathfindingGridBuilder which also has the core API for path requests

Grid Settings

Grid Builder Here you can configure the pathfinding settings that will be used with this grid.


Pathing Algorithm: Which algorithm will be used when generating paths with this grid.

Show Gizmos: Show gizmos for the grid cells & obstacles?

Cell Size: the world size of a grid cell.

Grid Size: the number of cells (width x length) for each side of the grid.

Collision Settings: Configure how obstacles are detected. Collision is generate by calling Build on the grid.


Usage

Try changing the algorithm selected on the PathfindingGrid and click "Build" again to see the effects of each.

Grids only need to be re-built when the obstacles that have collision change.

Move the start and target then click and then click "Generate Path" on the agent each time to see the new path.

Paths are rebuilt anytime you want a new path (target changes position, dynamic obstacles change, agent position changes off the path)

In PlayMode the grid will be built automatically when you try to generate a path from the agent (on DemoPathingAgent), you can also click MoveAlongPath to move in discrete steps toward the target. More of this movement is covered in the City Sample