MPath
High-performance A* pathfinding for 2D grid-based navigation with minimal garbage collection overhead. Optimized for real-time game development, MPath delivers exceptional speed and memory efficiency compared to alternative implementations, making it ideal for games requiring responsive AI pathfinding at scale.
com.migsweb.mpath 
Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/mpath.git?path=src/mpath-unity-project/Packages/MPath README Markdown
Copy this to your project's README.md
## Installation
Add **MPath** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/mpath.git?path=src%2Fmpath-unity-project%2FPackages%2FMPath
```
[](https://www.pkglnk.dev/pkg/mpath)README
MPath
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.
Features
- 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.
Benchmarks
| 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.
Installation
Unity (via OpenUPM) - Recommended
Option 1: Using OpenUPM CLI
- Install the OpenUPM CLI
- Run the following command in your Unity project folder:
openupm add com.migsweb.mpath
Option 2: Manual Installation via manifest.json
- 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)
Option 1: Using Package Manager Console (Visual Studio)
Install-Package Migs.MPath
Option 2: Using .NET CLI
dotnet add package Migs.MPath
Quick Start
Here'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!");
}
Documentation
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.
Important Notes
- Always dispose
PathResultobjects after use (useusingstatements) - Reuse the pathfinder instance for best performance
License
MPath is licensed under the MIT License. See LICENSE for details.
No comments yet. Be the first!