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
Navmesh 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
Support for navmeshes
Support for creating your own procedural grid generators
Performance
For example: A path with 168 points and which searched 316 nodes took about 0.1 seconds to complete, it was spread over 10 frames.
Another more complicated example: A path with 156 nodes and which searched 3730 nodes took about 0.43 seconds to complete and was spread over 42 frames. These example show much longer paths than you are likely to need (in case you are not making an RTS game).
An example which is a bit more normal goes like this: A path with 33 nodes took about 0.006 seconds to complete, it was spread over 1 frame and searched 162 nodes.
Results can very very much depending on computer specs and things like that, so it is hard to give a good example.
These tests were done in the Unity editor using an iMac G4.
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.5
Documentation
All Docs
FAQ
How do I use my code with the A* script?
API and components
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[dot] g[at]me[dot]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.
Hi Aron, been using your system since back in september and its been working brilliantly so far, however ive just tried to update my RTS project to 2.5 that you just released. Im getting 2 errors which i have previously never encountered:
Assets/Editor/AstarPathEditor.cs(353,43): error CS0117: `Selection’ does not contain a definition for `activeObject’
Assets/Editor/AstarPathEditor.cs(354,57): error CS0117: `Selection’ does not contain a definition for `GetFiltered’
Im not exactly sure what this relates too, all the new scripts are in the same folders they were in previously when they worked with the last version of the pathfinding. The Editor Default Resources folder is correctly placed such as the example project that you created, so im unsure exactly whats causing these errors.
I dont suppose you know whats causing these errors ?
Cheers
Jordan
Hi Jordan
Are you sure you are using the latest version of Unity (2.61)?
Or are you using Unity iPhone? In Unity iPhone, editor scripts wont work, but if that was the case you would probably have gotten a bunch of other errors too.
Hey again, just realised ive only got unity 2.6 ^^ updgrading it to 2.61 now , its not the i-phone version either. Ill post back if this doesnt fix it, but it probably will i just missed what version was required .
Cheers
Jordan
Hi again, again. Upgrading unity to the most recent version doesnt seem to have fixed these errors sadly, still getting the same 2 as above.
Jordan
Weird…
Well, if you have got the latest Unity version, and you are not using Unity iPhone, then Selection should contain those definitions, I have no idea why it doesn’t work on your computer.
Is it working in the example project when you haven’t changed anything (re-download it if you have changed something)?
Maybe it is a Unity bug.
Aron
it works fine within the example project, thats one of the first things i checked when it didnt work. I have tried reimporting all the scripts again and that hasnt work either. The folder structure is identical to the example project, bar the AstarPath/math/classes and seeker files, which are in the standard assets folder so i can access them with javascript, however i still receive the same errors if they were in the Pathfinding folder.
Aditionaly i havent changed anything within the scripts themselfs.
Cheers
Jordan
Try to delete all the pathfinding scripts and folders, and then importing a package named allRequiredAssets2_5.unitypackage which should exist in the example project folder (outside the assets folder).
Aron
Hey, seems ive found the solution now, i forgot i allready had a file named Selection deep inside some load of subfolders in my project, I think this would make a difference, ive since renamed it and the errors disapear. Just threw me off scent as they point to lines within the Astar script itself. Seems that you cant name a file Selection, but o well
fixed now.
Cheers for your help
Jordan
Ah, great that you solved it!
No, I would not recommend naming a file Selection, one of Unity’s editor classes is also named Selection.
[...] Aaron acaba de publicar una nueva versión del algoritmo A* para calcular caminos en http://www.arongranberg.com/unity/a-pathfinding/ [...]
Hi Aaron,
I wonder if you have plans to release an Unity iPhone version?
Theres a lots of Unity iPhone users willing to pay for this, thus us too.
You could automatically put the iPhone version in a commercial state and sold it entirely, no need to be free.
Admin: AFAIK the A* Project works with Unity iPhone, I haven’t tested it myself but others have said it works perfectly, although the custom editor does not work since Unity iPhone doesn’t use the new UI which makes stuff a bit more complicated, but does still work.
I have just started using the A* Pathfinding system. I’m very impressed. I do have one question, does it support multiple adjacent grids in a single scene? For example, could I have a mesh grid and a list grid in the same scene and find a path across the grid boundaries?
Thanks
Hey Aron,
Awesome program, I love it – I’m not very good with scripting, so I apologize if this is really easy, but I’m wondering what the procedure would be to allow the character to move towards the clicked point even if the player clicks on a non-walkable area or in another zone.
For example: if I have two zones with no connections between them (say, a wall is in the way), and I click on the zone that the character is NOT in, would it be possible for the character to walk as far as he could towards the click, and stop when he can’t go any further?
So the character will walk somewhere, no matter where you click, even if he can’t get there.
Thanks a lot
@Gonomonon
Sorry, currently that is not possible, it is on my ToDo list for the next version though.
@Kevin
Sorry, this is not possible at the moment, I have it on my ToDo list for the next version though.
However, you could code it up yourself using a procedural grid, but that might be a bit hard.
Aron,
Thanks, I’ll have to wait then.
If I could suggest something that i think would allow that to work, and also be useful for other things (in my opinion)
It would be nice if the user could assign an individual walkable node (or group of nodes, or hand placed links) to any given target that you click on.
For instance, you could set up a invisible geometry cube or trigger, and then tell A* to assign a path node that the character would walk to if the player clicked on that cube.
It seems like that might allow the user to kind of “direct” where the character goes in a given situation.
But, as I said, I’m no programmer – maybe I’m way off ^_^
Thanks again