A* Pathfinding
The focus for the A* Pathfinding project is to provide an out-of-the-box pathfinding system.
The system is easy to set up and it scans the surroundings automatically.
Terrain Demo
Building Demo
Features
Easy to set up
Requires no external data or code libraries
Very fast (see performance)
Can use multiple grids
3D pathfinding is supported
Runtime changing of the grid, for example placing a building on the ground
Node linking
Free for non-commercial projects (see license for info about commercial use)
Can execute over several frames
Path caching
Path simplification
Performance
For example: A path resulting in a path with 83 nodes, searched about 660 nodes took 5 frames or 0.00603 seconds with 0.0015 seconds/frame
Another shorter path resulting in 45 nodes and searched 345 nodes took 1 frame or 4.196167E-05 seconds, i.e so short time I couldn’t measure it.
A quite complicated path, 152 nodes long, searched 20 268 nodes, took 0.28 seconds split over 15 frames.
Results can very very much so it is hard to give a good example.
Licence

A* Pathfinding by Aron Granberg is licensed under a Creative Commons Attribution-Noncommercial 3.0 Unported License.
If you want to use the code for commercial projects please contact me at aron.g@me.com.
A license to use the project/code in commercial applications/games costs US $100, although other options such as profit sharing can be discussed if that suits the person/company in question better.
Download
Download A* Pathfinding Project version 2.2
Documentation
FAQ
Interface
How do I use my code with the A* script?
API
If you have any questions or things you would want to see added to the system, please post it as a comment or write to me at aron.g@me.com.

Real nice job. This is exactly what the unity community needs. Have you had a look at the community RTS project? Maybe you’d like to implement your system there.
Wow, really nice job!
Works almost perfectly, the only thing is that i sometimes get a null reference exception here
ath..ctor (UnityEngine.Vector3,UnityEngine.Vector3,single,single,bool) (at Assets\Scripts\Pathfinding\AstarPath.cs:258)
Seeker.StartPath (UnityEngine.Vector3,UnityEngine.Vector3) (at Assets\Scripts\Pathfinding\Seeker.cs:53)
the code works perfect for controlled units, but if i estabilish waypoints form them to follow (i get the path from one waypoint to another), it gives me this exception, apparently its about the maxFrameCount
if you could help on this i would appreciate a lot
@Gaba
The only scenario I can think of when this would happen is when you try to find a path in the Start or Awake function, since the variable “active”, also used in that line, is first set in Start, supposing you haven’t changed anything in the code.
Hope that will help : )
[...] and his website, http://www.arongranberg.com/unity/a-pathfinding/ [...]
[...] i had to update my project and implement the most recent version of the A*Pathfinding system from, http://www.arongranberg.com/unity/a-pathfinding/ , Its been updated also and is much more fluid than the last, as previously the unit would stick [...]
How can be A* used for commercial purposes ?
If you mean: “what commercial application types can it be used in?”:
A* pathfinding is used very often in RTS games and sometimes in TD games too, a lot of them are commercial.
If you mean: “What shall I do to be able to use the A* project for commercial purposes?”:
Send a mail to me [aron.g@me.com].
[...] signale la sortie de la dernière version de A* Pathfinding. Il s’agit d’un projet complet permettant de créer un pathfinding dans votre jeu, en [...]
Hi, Im new in Unity3d. How I setup the A* pathfinding? thkz!
You can download the example project to see an example of the A* system in action.
The documentation page has a page about how to use your own scripts with the system.
To set up the system in a new scene, it’s simply just to create a new gameObject and add the AstarPath script to that object.
Excellent addition mate! This will relieve many a headache when it comes to achieving those game development dreams. Keep up the good work!
Nice Job! This is exactly what i needed. Implementation worked very well, thank you!
[...] is the A*Pathfinding Project from Aron Granberg. Installation and implementation worked very well without any bigger [...]
Hi i was wondering if the Astar Path code worked on any type of terrain because I have tryed a few time but just cant get it to work i keep getting the same error
No nodes are walkable (maybe you should change the layer mask)
UnityEngine.Debug:LogError(Object)
AstarPath:Scan(Boolean, Int32) (at Assets\Garden AI\AstarPath.cs:1243)
AstarPath:Start() (at Assets\Garden AI\AstarPath.cs:238)
Yes it does (maybe I should write Get Started page…)
The reason you are getting that error is probably because the script thinks the Terrain is an obstacle and thus making the nodes unwalkable.
To make it work, place the terrain in a certain layer, “Ground” for example, then change the layer mask in the Walkable check settings to exclude the “Ground” layer, then the script won’t think the ground is an obstacle.
Take a look at the terrain scene in the example project for a fully working setup.
Thnx That will help alot
Hi,
I’ve downloaded A* Pathfinding and am quite confused. Is there any tutorial how to use this system at all? How, for example install it in Unity? How to generate navmesh? etc. The only thing I found in documentation folder is four png images, is it supposed to be a documentation?
That’s what I am writing right now, documentation.
For the release of version 2.5 I want to have a good “Get Started” guide, so hold on, the docs are not far away ; )
Meanwhile, if you have any specific questions you can post them as a comment in the FAQ page.
Then I am looking forward detailed documentation to be relesed. I wish you all the best in your job.
As for specific questions, could you please tell how to install pathfinding in Unity? I can not find any pathfinding specific dialogs (shown in the screenshots) in Unity. It seems some plugin should be installed or I am wrong? On the other hand, the archive I’ve downloaded contains only assets and library folder (besides documentation) should I copy them to my project directory? I would like to keep project directory as “clean” as possible – no additional fbx, material, blender files etc. needed – is there anywhere a basic package that only contains necessary items, without additional models and such things?
The folder you have downloaded is a complete unity project, to open up the project double click on the unity level file in Assets–>Terrain (maybe Assets–>_Scenes–>Terrain).
You should have a look at these example scenes before you add it to your own project.
To download only the necessary files, go to the download page and download the Unity package for upgraders, open your project in Unity and double click on the .unitypackage file to import the files. To add the A* script to a project, drag the AstarPath script to an empty gameObject and you should see the full editor controls there.
WARNING: Don’t copy the library folder to another project, I did that once an Unity got a “Critical Error” message.
I was wondering what the status on the “Getting Started” guide is? I really want to use this for a project but I am a noob and need some help getting started
@Willem
Here’s the link for the current version of the “Getting Started” guide, the only problem is that the guide is written for 2.5 and not 2.2 which you are using, but you can probably get something out of it anyway
http://www.arongranberg.com/unity/a-pathfinding/docs/get-started/
Hi Aron, I was just wondering if you could tell me if it’s possible, and if so how, to manually add in the nodes that make up the NavMesh instead of using prebuilt tools. The reason I ask is because I have a game that generates levels from tilemaps, they’re all flat and it’s essentially the exact same approach as used by the image example. I mean I could go through the gigantic hassle of encoding the info into a colour coded image then passing that through but obviously that’s rather absurd. Anyhoo thanks in advance for any help you can give on this area, i’ve implemented A* myself for this project but it’s not very well optimised and this is an iphone project so it’s somewhat important.
Hi Brian
I created a new grid generator based on the texture generator (5 minutes of work) just for you!
The only thing that changed is that it takes an array of booleans (true/false) to generate the grid along with width and depth variables.
Take a look at the ScanTilemap function when the system gets released (in the code).
Make sure you use the Texture mode and that the Calculate On Startup flag is set to FALSE, you will need to call the function yourself to generate the grid since it needs some extra data (bool array).
PS: Want to beta test the new system? The release is very near but I need some to test the system since I don’t think that I can debug the system all by myself.
Brilliant! Thanks alot, ofcourse i’d be happy to test it, having a reliable, latent processing pathfinder will be of immeasurable help so i’m glad to help in any way I can. You can contact me at ******* (removed)!
Hi, I am working on intelligents agents and want each agent to calculate an optimal path in a terrain that is unique to each agent. Consider ten robots positioned in the same physical terrain. Each robot has its own target position and an internal representation of the terrain called an “abstract map.” That is, each robot views the landscape with their own eyes and sees the terrain differently. Therefore I am currently generating ten extra maps (ten unique terrains) and adding the AstarPath script to each map, with the idea that each robot plans an optimal path based on their own abstract map.
Is it possible to use more than one AstarScript at the same time? Do you have any other suggestions for my idea?
Hi Robin
The AstarPath script is a singleton class, so you can’t use more than one in each scene.
What you can do (when 2.5 comes out) is to make multiple grids which raycasts and hits different layers, thus giving you 10 different maps.
In 2.5, the seeker script will have a variable called Grid Selection, by default this is set to Auto, with that setting it chooses between all grids, but you can set it to Fixed and change another variable, called just “Grid” to the grid index you want it to search.
For example you want one agent to operate on grid 3 (number four in the grid list, remember an array starts on 0), you set “Grid Selection” to Auto and “Grid” to 3, then that seeker will only search the fourth grid.
You will only be able to follow these instructions when 2.5 is released, hopefully this week.