Skip to content

migus88/MPath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MPath

License: MIT Version

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

  1. Install the OpenUPM CLI
  2. Run the following command in your Unity project folder:
    openupm add com.migsweb.mpath
    

Option 2: Manual Installation via manifest.json

  1. Open your Unity project's Packages/manifest.json file
  2. 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
      }
    }
  3. 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:

  1. Open the Package Manager window in Unity (Window > Package Manager)
  2. Click the "+" button and select "Add package from git URL..."
  3. 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)
  1. Download the latest .unitypackage from the Releases page
  2. 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:

The API reference provides detailed information about all public classes, interfaces, and methods, with examples for each component.

Important Notes

  • Always dispose PathResult objects after use (use using statements)
  • Reuse the pathfinder instance for best performance

License

MPath is licensed under the MIT License. See LICENSE for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published