A high-performance A* implementation for 2D grid navigation, designed primarily for game development (especially Unity) but fully compatible with any .NET project. MPath is optimized for speed and minimal memory allocations, making it ideal for real-time applications.
- Fast A* pathfinding with near-zero garbage collection overhead
- Allocates memory only when necessary to maximize performance
- Designed for 2D grid-based navigation in games
- First-class support for Unity with dedicated integration components
- Fully usable in any standalone .NET application
- Extensively tested with comprehensive unit tests
- Includes performance benchmarks
⚠️ Note: MPath is not yet thread-safe and should not be used across multiple threads.
| Method | Mean | Allocated |
|---|---|---|
| MPath | 5.092 ms | 24.06 KB |
| AStarLite | 8.118 ms | 8.74 MB |
| RoyTAStar | 59.028 ms | 12.29 MB |
| LinqToAStar | 5,532.7 ms | 108.13 MB |
For detailed information about MPath's performance benchmarks, including implementation comparisons and path smoothing options, see the benchmarks documentation.
Unity (via OpenUPM) - Recommended
- Install the OpenUPM CLI
- Run the following command in your Unity project folder:
openupm add com.migsweb.mpath
- Open your Unity project's
Packages/manifest.jsonfile - Add the OpenUPM registry and the package to the file:
{ "scopedRegistries": [ { "name": "OpenUPM", "url": "https://package.openupm.com", "scopes": [ "com.migsweb.mpath" ] } ], "dependencies": { "com.migsweb.mpath": "1.0.0", // ... other dependencies } } - Save the file and Unity will automatically download and install the package
Unity (via Git URL)
Add MPath to your project via the Unity Package Manager:
- Open the Package Manager window in Unity (Window > Package Manager)
- Click the "+" button and select "Add package from git URL..."
- Enter the following URL:
https://github.com/migus88/MPath.git?path=/src/mpath-unity-project/Packages/MPath
To use a specific version, append a tag with version (e.g 1.0.0) to the URL:
https://github.com/migus88/MPath.git?path=/src/mpath-unity-project/Packages/MPath#1.0.0
Unity (via .unitypackage)
- Download the latest
.unitypackagefrom the Releases page - Import it into your Unity project (Assets > Import Package > Custom Package)
.NET Projects (via NuGet)
Install-Package Migs.MPathdotnet add package Migs.MPathHere's a simple example of using MPath in a .NET project:
// Create matrix of Cells
var cells = new Cell[10, 10];
// Or do it with gameObjects that implements ICellHolder
[SerializeField] private FieldCell[] _cells;
// Create a simple agent
var agent = new SimpleAgent { Size = 1 };
// Or your own player controller that implements IAgent
[SerializeField] private PlayerController _player;
// Create a pathfinder
_pathfinder = new Pathfinder(cells);
// Optionally pass a configuration file (see docs)
_pathfinder = new Pathfinder(cells, config);
// You can also enable path caching
_pathfinder.EnablePathCaching();
// Find a path
var start = new Coordinate(1, 1);
var end = new Coordinate(8, 8);
using var result = pathfinder.GetPath(agent, start, end);
// Use the path
if (result.IsSuccess)
{
Debug.Log($"Path found with {result.Length} steps!");
}MPath comes with comprehensive documentation:
- Getting Started Guide - Overview and basic usage
- API Reference - Detailed class and interface documentation
- Integration Guides - Specific guides for Unity and .NET projects
The API reference provides detailed information about all public classes, interfaces, and methods, with examples for each component.
- Always dispose
PathResultobjects after use (useusingstatements) - Reuse the pathfinder instance for best performance
MPath is licensed under the MIT License. See LICENSE for details.