A* FAQ

I get red dots all over the map when I try to generate the grid!

There can be two things causing that:
1. If you are using Raycast mode in the Y position settings:
The layermask for the Y position might be set up wrong: Make sure your walkable ground is in a layer which you have specified as walkable in the Y position layermask.
A quick way to see if this part is the problem is to check if the red dots follow the ground, if they do, this isn’t the problem, and if they don’t this is the problem.

2. The physics layermask might be set up wrong: For each grid there are physics settings, these define what is an obstacle and what is not, and it also defines how to search for obstacles, make sure your walkable areas are in a layer which is ignored by the physics settings (put all the objects the player should be able to stand on in a separate layer if you haven’t done so already), otherwise it will think that the ground (or other walkable areas) are obstacles and will thus flag them as unwalkable (red dots).



I’m using terrain mode and the grid isn’t generated correctly! And I get an error message saying something about a 60000 vertex limit.

That is because the terrains GetHeight function does not support terrains with more than 60K vertices, to solve this you need to use Raycast mode, put the terrain in a separate “Ground” layer, and then change the raycast’s layermask to only include that layer.

11 Responses to A* FAQ

  1. SNoChE says:

    Hi,

    I have a few questions:

    I am using pathfinding 2.5 in my project. I am having lots of errors messages (clicking outside etc…), so far I commented all the Debug.error lines to play the game, is there a way to set any global variable to do that?

    Are you planning to avoid Sendmessage in next versions? (maybe using a good Deleagate based event manager?)

    Also if I change some code (not pathfinding code) in visual studio and come back to unity, pathfinding breaks. This is very annoying, do you know how I could fix that?

    (I am using Grid, with capsule and raycast.)

    this is the error line

    NullReferenceException: Object reference not set to an instance of an object
    AstarPath.GetNode (Int32 x, Int32 y, Int32 z) (at Assets\-Scripts\Pathfinding\AstarPath.cs:969)
    AstarPath.GetNode (Int3 pos) (at Assets\-Scripts\Pathfinding\AstarPath.cs:965)
    AstarPath+Path.PostNew (Int3 startPos, Int3 endPos) (at Assets\-Scripts\Pathfinding\AstarPath.cs:622)
    AstarPath+Path..ctor (Vector3 newstart, Vector3 newend, Single NmaxAngle, Single NangleCost, Boolean NstepByStep) (at Assets\-Scripts\Pathfinding\AstarPath.cs:589)
    Seeker.StartPath (Vector3 start, Vector3 end) (at Assets\-Scripts\Pathfinding\Seeker.cs:151)
    Clicker.Update () (at Assets\-Scripts\Pathfinding\Clicker.cs:80)

    Mesh option could be better technique than grid? how about the performance between this 2?

    Thanks in advance.

    PS: looking fordward to proper documentation and new version.

  2. Admin says:

    Hi SNoChE

    Do you mean that the game pauses when an error occurs, and that’s the problem?
    If so, there is a checkbox at the top of the console window called “Error Pause”, if you uncheck that, the game wont pause on errors anymore.

    Good idea using delegates instead of SendMessage, I will look in to that. Thanks.

    This has just been answered in the latest (5′th page first post) post in the release topic:
    http://forum.unity3d.com/viewtopic.php?t=43822&postdays=0&postorder=asc&start=60

    The performance difference depends only on the number of nodes which needs to be searched.
    Mostly, navmeshes have fewer nodes than grids, however grids can use Array Positions for distance determination (the nodes are placed in a 2D array) since the nodes world positions are proportional to the array positions, and that’s a bit faster than using World Positions (ints are faster to process than floats).

  3. AlbertoZ says:

    Hi!

    Gratz for this amazing code! is a real gem of code.

    Everything works perfect on my side, except when I try to set up more than 3 objects to follow the player. If I have 4 objects, 1 of them don’t perform the path finding, but if I erase any of the objects at random having only 3 present at the scene, all works fine.

    Is there any maximum of objects that can path finding at the same time on the same scene?

    Thanks in advance!

  4. Admin says:

    There is no maximum of objects that can pathfind at the same time.
    However problems can occur if you set them to perform pathfinding as often as possible, the script doesn’t have a real queue for the incoming pathfinding calls, it’s just a bunch of coroutines checking every frame if there is no other pathfinding executing at the same time, and if there is none, executes the pathfinding.

    The problem occurs when there constantly are like 3 coroutines active at the same time, possibly one script might always get executed before another script and thus will always know which way to go, while the other script never get’s a single path calculated.

  5. Dan says:

    I have a short question. In my map is a bridge where you can go beneath the bridge as well as across it. I was wondering how I can handle this. Do I have to create two grids for this?

  6. Admin says:

    Yes you have to create two grids for this.

    Each grid is only in 2D and cannot handle for example bridges.
    If you create one grid for the stuff beneath the bridge and then one grid for the stuff at bridge level it will work, you can stitch them together with links.

  7. Adam Waters says:

    Hey Aron,
    I’m trying to bring your path finding scripts into my project, but I can’t get past this error:
    The type or namespace name `AstarData’ could not be found. Are you missing a using directive or an assembly reference? (CS0246) (Warlord)

    I’m adding the scripts to a Mono project, since AstarData is an Asset, I almost expect to get that error. But once I import the astarData.asset into unity it still won’t let me add the script to objects.

    Any ideas?

  8. Quazi Irfan says:

    Hi, thanks a million for this awesome product.

    I have some questions,

    1. How to trigger an event while the Player started moving.i.e. When my human character is moving i wanna play the walk cycle animation.

    2. When I click on an unreachable part on the map then the game is paused.I don’t want it in that way.I want the player will remain in it’s position and an error will be printed saying “Unreachable!”?

  9. Admin says:

    1. How to trigger an event while the Player started moving.i.e. When my human character is moving i wanna play the walk cycle animation.
    You can make use of the “command” variable on the AIFollow script.
    Make your script play the walk animation when the command variable is set to Command.Walk.

    2. When I click on an unreachable part on the map then the game is paused.I don’t want it in that way.I want the player will remain in it’s position and an error will be printed saying “Unreachable!”?
    Switch off “Pause On Error” in the Console window.
    You can implement the “PathError” function in any script attached to your player and make that draw the Unreachable label.
    function PathError () {
    drawUnreachableLabel = true;
    }

    Sorry for answering late, I have been (and am) on holiday, but I’m home for one day so I will try to answer as many comments as possible.

  10. Nathan says:

    Hi Aron,

    Thanks for a great product. I am trying to evaluate the it as a possible solution in a small game I am working on but I am just having some trouble calculating paths.
    I have followed the tutorials and have a valid grid with a set of objects that are non walkable however every time I try and calculate a path I get ‘Start is not inside any grids’ warning.

    The bounding box for the grid encompasses my model so the pivot point appears to be inside the bounds but I cannot seem to ever find a path. Just in case it is relevant, my model is a biped with pivot points at the hips.

    Any advice would be helpful.

  11. Nathan says:

    Just an update on the above issue. It turned out I was not using Pivot view to check the bounds of the grid so the actual pivot in Unity at the bottom of the character was out of bounds. A silly mistake on my part.

    Now if only I could get a character to randomly wander around without any intervention I would be set :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>