1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

Pathfinding in unity: First Path 1.0 tutorial now available!

Discussion in 'Made With Unity' started by AngryAnt, Mar 18, 2009.

  1. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    With the launch of unity 2.5, I can finally share this leap from Path 0.3b. Check it out at http://angryant.com/path/

    Specs:
    - Available for unity indie as well as pro licensees
    - Can run in webplayers as well as stand-alone
    - Requires no additional installations

    Features:
    - Easy to use editor interface
    - Navmeshes
    - Waypoint networks
    - Cached pathes
    - Distributed processing using coroutines
    - Tag-filtered pathfinding
    - Hierarchal “grid network” pathfinding
    - Auto-recalculate on runtime network changes

    [​IMG] [​IMG] [​IMG]
     
  2. Matroblend

    Matroblend

    Joined:
    Jan 30, 2009
    Posts:
    134
    I just received the win 2.5 pro version of Unity and I have watched your demo vids Great work. I can't wait to get a grip on Unity to test your work.

    Thank you very much
     
  3. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    964
    Congratulations with the release! Will put it to good use soon.
     
  4. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,493
    Good on you Emil, these add-ons you make are very constructive.

    Aaron
     
  5. Scrat

    Scrat

    Joined:
    Apr 20, 2008
    Posts:
    316
    Great, Congrats!

    What's the licensing terms? I couldn't find it on your website.
    IIRC it's just your logo at the beginning of the game?
     
  6. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    Click to download one of the files - you'll be directed to a view of the license which you have to accept before downloading.
     
  7. loadexfa

    loadexfa

    Joined:
    Sep 2, 2008
    Posts:
    206
    I'm looking forward to how awesome the new Path will be. A quick web design note, I couldn't find the download link for like 5 minutes. I may be a bit dense but it would probably help to make it more obvious somehow. In my mind it just kinda blended with the header and I wasn't looking there.

    Thanks for Path!

    Josh
     
  8. amcclay

    amcclay

    Joined:
    Aug 8, 2006
    Posts:
    143
    Hey Emil, amazing work.

    Any idea when you might have some docs or a quick write up? I can't figure out how I would go about incorporating my own nav mesh into your system.

    I can see it has something to do with the 'Create' menu in the Path browser, but other than that, I'm not sure.

    Thanks!
     
  9. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    I *just* finished the first video tutorial and its available on the Path documentation site :) Get it while its hot!
     
  10. Matroblend

    Matroblend

    Joined:
    Jan 30, 2009
    Posts:
    134
    Just watched the first tutorial very impressive, I look forward to testing as soon as I can get enough of our project mapped from our previous pipeline to our Unity pipeline.
     
  11. tolm

    tolm

    Joined:
    Feb 4, 2008
    Posts:
    61
    Nifty! I'd be real interested in knowing how you made the small bar at the top of the path browser. Is there a built-in way to make such bars, or are you "faking" it with a custom GUIStyle?
     
  12. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
  13. tolm

    tolm

    Joined:
    Feb 4, 2008
    Posts:
    61
    Thanks! What I was looking for was the "Toolbar" and "toolbarbutton" GUIStyles. Hadn't thought of going through the styles in the built-in skin. :oops:
     
  14. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    346
    hi there, thanks for the great work,
    but this doesn't work for the new 2.5(windows trail)?
     
  15. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    Was that a question or a statement? Path 1.0 *only* works on 2.5 and I haven't had any reports of problems from people who have used it on their windows installs.
     
  16. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,493
    Can you please try downloading your UnityPackage Emil? Its getting corrupted by the unzipping process, the trick is to put package into folder, then zip said folder. Currently it unpacks as gobbledygook..for me at least-this has always been the case with unityPackages in my experience.

    Cheers
    Aaron
     
  17. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    346
    hi there,but when i import the path package unity
    said that can't decompress the package?
    i used the windows 2.5 trial version.
     
  18. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    Ah - sorry I was unaware of that issue. I uploaded a new zip containing the package in a folder.

    Notice that for your first tests I recommend you use the editor demo project which already has a Path collection setup.
     
  19. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    So... Who really got around to trying this out? Are y'all happy or what? Feedback wanted.
     
  20. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    160
    The video tutorial looks great, I've downloaded 1.0 and I'm trying to get stuck into it, but I'm having problems.

    When I create a Waypoint in a WaypointNetwork, I can't change the position of it - it keeps snapping all x, y and z values back to zero. I tried opening your demo project to see what I was doing wrong, but the same issue appears there. Is there something obvious I'm doing wrong or could this be a Unity 2.5 related bug?

    Also - not really critical but I noticed that PathEditor keeps getting leaked in the editor.

    EDIT: It works (as in you can move the waypoints) you just can't edit the fields in the inspector. That would be useful but I guess it isn't critical.
     
  21. twitchfactor

    twitchfactor

    Joined:
    Mar 8, 2009
    Posts:
    327
    Really looking forward to this and your state machine editor (Behave), since I'm going to try and make a Metal Gear Solid clone in Unity.
     
  22. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    160
    Hey,

    Got it all set up and it's working great! Congrats on the 1.0 release. :)

    Got a question though:

    I want a system where NPCs can navigate either using Path for complex environments (will always be WaypointNetworks), or a 'free roam' mode for open areas where pathfinding would be an unnecessary waste of server resources. I've noticed that when a GameObject with a Seeker is not in any of the Path networks and starts a Seeker, none of the ISearchMonitor events get called to tell you that there isn't an available path to the destination. Is there a way on querying the Seeker to find this out? Or do I need to come up with a separate system to test whether the NPC is within a Path network bounding box before starting a Seeker?
     
  23. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    twitchfactor:
    Groovy. Sounds exciting :) Notice that Behave facilitates authoring and use of behaviour trees and not finite state machines - I warmly recommend you check out aigamedev.com and specifically the video I link to there from my site to learn about the advantages of behaviour trees vs. finite state machines :)



    Nekharoth:
    Regarding waypoint positioning: Ugh. Clearly a bug. Thanks for reporting it - first I heard of it.

    Regarding no-waypoints scenario:
    If you're in no-node land, you'll know as soon as you've constructed your seeker. If your start position is outside the bounding boxes of your networks, yourSeeker.Start will be set to null and the same with the destination and yourSeeker.End.

    Alternatively, if you'd like to use the ISearchMonitor events, you could place a waypoint network, the bounding box of which contains your area, with a single waypoint in it at some random location. In that case, starting your seeker will result in it completing immediately and returning an empty path (since the start and end nodes equal).

    Notice that in the first approach, you have a problem if your start position is outside any known network, but your end position is within a network (which then would need pathfinding).

    In the second approach, same scenario, you would receive a path from the single node in the network and onward if you have the network connected to the other networks via a grid network - if not, the seeker will fail (no way to get from current network to destination network).

    If you do want to mix simple areas and areas needing pathfinding, I would recommend you set up a waypoint network for the simple area with nodes along the network borders where you want connections to other networks. And then set up a grid network to handle these connections.

    This should give you empty pathes when seeking within the simple area and pathes using the border nodes when seeking to more densely networked areas.
     
  24. verbatimline

    verbatimline

    Joined:
    Mar 24, 2009
    Posts:
    88
    Great work, I am really interested to see it in action. Do you think you could create a movie of Path in action for those who are new to game programming and games in general?
     
  25. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    160
    Thanks for the feedback and ideas. I think that's exactly the solution I was looking for, I'll set it up and test it tonight.
     
  26. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    Groovy. I just thought of an issue you might have with that solution:

    If the nearest node of your from and to positions turns out to be two different border nodes, you'd get a path between those two nodes even though you're navigating in the "simple area".

    One workaround for this could be:
    A) Add a "no navigation" or similar tag to the network for the "simple area".
    B) When you receive a seeker result, add this:
    Code (csharp):
    1. if( mySeeker.Solution.Count > 0  mySeeker.Start.Network == mySeeker.End.Network  mySeeker.Start.Network.HasTag( "no navigation" ) ) // (or whatever you named the tag)
    2. {
    3.     mySeeker.Solution.Clear();
    4. }
    That should take care of this issue.
     
  27. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    160
    Thanks for the tip, but I'm not even getting that far. :(

    I must be doing something wrong - if I start a seeker on an NPC in the "simple" area, it calls OnSearchFailed. I've got a grid network with connections to the "complex" area, but it just seems to be ignoring them - even if I put the NPC inside one of the border nodes.
     
  28. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    Could you make your Path asset available somewhere so I could take a look?
     
  29. varmint

    varmint

    Joined:
    Nov 30, 2008
    Posts:
    15
    Very kewl, I've been using Path for a few days now on a single level and today did some end to end testing with in our game.

    First time I go into the level were I have Path. I get the message
    "AngryAnt Path 1.0 - loaded collection. Network count now up to 1." Which is great :D

    If I leave that level and then return I get:
    "AngryAnt Path 1.0 - loaded collection. Network count now up to 2."

    There is only one network on this level.

    I looked in the PathControl.cs script. In the Awake function there is:
    Code (csharp):
    1. Control.Instance.Init( this );
    2.        
    3. Control.Instance.LoadCollection( pathAsset as IPathAsset );
    Is there an unload? or something to destroy the Instance?

    As a test I added Application.LoadLevel button to the DemoControl.cs in the Editor demo for Path 1.0
    Code (csharp):
    1.  
    2. if( splashAlpha <= 0.0f )
    3. {
    4.   if( GUILayout.Button( "LoadLevel" ) )
    5.   {
    6.     Application.LoadLevel("Default");
    7.   }
    8.  
    9.   advanced = GUILayout.Toggle( advanced, "Advanced", GUI.skin.GetStyle( "Button" ) );
    10.  
    11.  
    Each time you click it, the network load count doubles.
     
  30. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    There is currently no way to unload collections :oops:

    What you *can* do is condition collection load on the existence of a network in that collection:

    Code (csharp):
    1. if( Control.Instance.GetNetwork( "NetworkFromMyCollection" ) == null )
    2. {
    3.     Control.Instance.LoadCollection( pathAsset as IPathAsset );
    4. }
     
  31. varmint

    varmint

    Joined:
    Nov 30, 2008
    Posts:
    15
    awesome that works :D
     
  32. Pia

    Pia

    Joined:
    Feb 16, 2009
    Posts:
    78
    When will the fix be released which allows setting waypoint coordinates in the Inspector?
     
  33. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    It'll be out with a bunch of other fixes and additions as 1.1 - don't have a date yet as I'm currently working on a new release of Behave.
     
  34. Pia

    Pia

    Joined:
    Feb 16, 2009
    Posts:
    78
    Ok, looking forward to v1.1 then, because I really like Path so far, quite powerful.

    One feature I would really like to see is the ability to create a waypoint at the mouse position with just one click, in a way which places the waypoint automatically on top of a collider (like terrain). So basically I want to place waypoints like one would do in a real-time-strategy game.
     
  35. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    Glad you like it :)

    I've added your feature request to my todo - not sure which hooks unity has to facilitate something like that but I'll see if I can work something out.
     
  36. ichinl

    ichinl

    Joined:
    May 20, 2009
    Posts:
    1
    Hello! I really like Path! It's a great way to make your NPC's move around. I've got one question though: I'm building a GTA-like city game with traffic and I'd like to use Path with waypoints to make the traffic drive around. The problem is now that I need up to 12 waypoints for one intersection. Would that be a problem for memory load?

    I'm also wondering if you know when version 1.1 will come out? I'd really like to change the position of the waypoints by editing the coordinates.

    Thanks for the great tool!
     
  37. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    Hey. I'm glad you enjoy the product. Twelve nodes is no trouble and generally you shouldn't worry about memory in Path - very little is used per node.

    Regarding 1.1, I'm quite pressed for time at the moment, but it'll be there.
     
  38. andygeers

    andygeers

    Joined:
    Jun 13, 2009
    Posts:
    30
    Hi there,

    Just giving Path a spin and it seems really great. Is there currently a way/any plans to make it so that you can "split" a navmesh into several different sections? e.g. I have a single landscape mesh with a stream down the middle of it, and want force seekers to cross at the bridge. Currently I can't really seem to do that very easily.
     
  39. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    Sure. Options sorted by optimisation:
    - Split the mesh in two and connect the two via a grid network.
    - Keep it as one big mesh and delete the polygon where the stream is.
    - Disable the navmesh cells where the stream is.
     
  40. andygeers

    andygeers

    Joined:
    Jun 13, 2009
    Posts:
    30
    Cool, I've got this working now.

    I think there are a couple of minor tweaks you could make that would make the UI a lot easier to use for this kind of workflow:

    * it'd be cool if you could select more than one nav cell at the same time so that you can tag/disable them one one batch (at the moment you seem to have to tag them one at a time, and it pops up a confirmation box for each one separately)

    * it'd be cool if you could select them by clicking in the 3D Scene View rather than having to guess which of your hundreds of nav cells is the one you want to disable

    * it'd be cool if once you've tagged a bunch of nav cells, you could reselect them all by tag

    But other than that, thanks for the great extension!
     
  41. pochimuffin

    pochimuffin

    Joined:
    Dec 8, 2008
    Posts:
    10
    Hi there,

    Just started working on Path for my game and it's really great. Unfortunately, I'm having a hard time making the navigation mesh. Basically, I have a terrain with a lot of narrow paths and a few 1-2 storey houses (a small village). I was able to do the navmesh for the narrow paths although sometimes, my seekers get stuck in sharp corners (90 degs.). Any tips on how to fix that?

    Also, I plan to use navmeshes for the houses so that seekers can go inside. Do you think that's a good idea or should I use waypoints instead?
     
  42. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    @pochimuffin:
    Hey. Glad you like it.

    Stuck on corners:
    I assume you're using the default seeker code provided in the editor demo project? Try expanding the radius on that and see if that helps.

    Navmeshes in buildings:
    Well if you need detailed movement, use navmeshes, otherwise waypoint networks. If your characters basically just need to run through the houses then you there would be no need for high resolution pathfinding, so a waypoint network would be just fine. If you're planning on doing some gameplay inside the houses, you should probably use a navmesh.

    Notice that a navmesh is not by itself slow computational wise. The thing is that its very easy to end up with a lot of polygons - meaning a lot of nodes. A simple navmesh is quite effective.
     
  43. andygeers

    andygeers

    Joined:
    Jun 13, 2009
    Posts:
    30
    Hi there,

    Having another play with Navmeshes. I may be doing this wrong, but it seems to me that they don't take into account any transforms you apply to your mesh. So if my base mesh is rotated or scaled then the nav mesh is lined up in the wrong place. Is that intentional? Should I just create a child gameobject and apply the path control to that?
     
  44. andygeers

    andygeers

    Joined:
    Jun 13, 2009
    Posts:
    30
    Is there any way to manually add custom cells to a Nav Mesh? I'm find the user interface a bit clunky (e.g. often I don't want to use the *whole* of the actual location mesh for the nav mesh, just a subset of it, which there is currently no way to do) and it'd be cool if I could just get on with making my own UI rather than burdening you with constant feedback requests.
     
  45. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    Unfortunately Path does not currently double as a mesh editor. You'll need to use your 3D authoring environment to optimise and customise your navmesh.

    Regarding transforms, no the transform is not taken into account apart from translation. You'll have to use your 3D authoring environment to transform the mesh and / or tweak the importer settings.
     
  46. teatime

    teatime

    Joined:
    Jun 16, 2008
    Posts:
    129
    since installing path i've encountered constant, predictable crashes (that don't even boot me out to the error log screen, unity just vanishes) when trying to rebuild meshes. i even tried deleting and reinstalling unity and path and it didn't help a bit. is this unheard of for everyone but me?
     
  47. andygeers

    andygeers

    Joined:
    Jun 13, 2009
    Posts:
    30
    Obviously I understand that Path should in no way be a mesh editor - what I'm proposing is a programmatic way to add extra mesh nodes through my own code. The problem is that my navmesh is somewhat decoupled from my visible geometry - e.g. I only want a tiny subset of the actual landscape mesh to form my navmesh, and at present I can't even see a way to delete navmesh nodes, let alone add new ones. (Edit: I've tried *disabling* nodes, rather than deleting them, but my mesh has so many polys that Path slows right down to a crawl if I try and use my mesh, whereas if I could delete them or only add a subset to start with this wouldn't be an issue)
     
  48. lankoski

    lankoski

    Joined:
    Apr 20, 2008
    Posts:
    148
    Meanwhile, you could check Lies and Seductions navmesh based wayfinding that includes very simple navmesh editor code. The code is available under Apache license at http://mlab.taik.fi/~plankosk/blog/?p=308.
     
  49. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,037
    What most people do is pull the mesh to a 3D authoring app (or in case of a landscape - pull the height-map and build a mesh based on that) and in there they apply simplification algorithms and manually edit the mesh so that it fits their needs.
     
  50. daodao

    daodao

    Joined:
    Feb 1, 2009
    Posts:
    16
    Since Unity Iphone support external assembly, I create path data asset in Unity 2.5 and then open the project in Unity Iphone and I was told this:

    ** (/Applications/Unity iPhone/Unity iPhone.app/Contents/Frameworks/MonoCompiler.framework/mcs.exe:11051): WARNING **: The class System.Collections.Generic.IEnumerator`1 could not be loaded, used in mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089


    It seems Path using dotNet 2.0 features which is not allowed in Unity Iphone. Can we avoid dotNet 2.0 features? Can I help on this?

    I also post the same question in http://forum.unity3d.com/viewtopic.php?t=10501. Because we are talking about Path 1.0, I think I should post here.