Search Unity

A* Pathfinding Project 3.0 is Released!

Discussion in 'Assets and Asset Store' started by half_voxel, Aug 10, 2011.

  1. Goldrake

    Goldrake

    Joined:
    Feb 6, 2010
    Posts:
    148
    Anyone can explain th differences between the Pathfinder of the new beta 3.5 and A* Pathfinding:
    1) the speed and performances
    2) the features

    than you very much
     
  2. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    @Goldrake

    I haven't got Unity Pro, so I cannot test the U3.5 pathfinder, but I know some things:

    Features:
    A* Pathfinding Project
    • Grid, Point and navmesh graphs, as well as support for scripting your own graph generators
    • Support for off-mesh links, but not that advanced
    • Exposes the graphs so changes can be made by custom scripts
    • Local avoidance based on ClearPath (which is similar to recasts system)
    • Support for changing the graphs during runtime, to for example implement moving obstacles, it is however more limited on navmesh graphs.
    • Multithreaded (at least in the pro version)
    • Open source
    Unity Pathfinder:
    • Only navmesh graphs
    • Good support for off-mesh links
    • Not much is exposed, from what I have seen, you cannot modify the graph very much using code
    • Local Avoidance based on Recast, currently works better than the one in the A* Pathfinding Project imo
    • No support for updating the graph during runtime (except changing some walkability tags)
    • No idea if multithreading is used actually
    • Not open source

    That's the differences I can think of right now.
     
    Last edited: Jan 6, 2012
  3. Goldrake

    Goldrake

    Joined:
    Feb 6, 2010
    Posts:
    148
    THank you very much sturestone.
    What i have to decide is which one is better regarding performances (mobile) to realize a crowd simulation (assassins creed like).
    I can't understand the differences between local avoidance and dinamic obstacle. For Obstacle is meant also moving characters/agents? Or that is the local Avoidance?

    Thank you
     
  4. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Dynamic Obstacles are dynamic changes to the pathfinding graph so agents find a path around it.
    Local avoidance does not change the graph, but instead steers away from other agents and adjust speeds to avoid collisions, this is faster and usually works better for crowd simulation but dynamic obstacles work better if you have a few large obstacles moving sometimes/slowly or if they have non-primitive shapes (usually local avoidance works only with circles/cylinders)
     
  5. why789

    why789

    Joined:
    Sep 23, 2011
    Posts:
    184
    I'd also like to know this...

    thanks,
    why789
     
  6. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Hm... didn't I answer that question some time ago.... apparently not...

    Anyway, 1) Yes it covers vertical environments.

    2) That depends on how much detail you want in the graph. For navmesh graphs I would say it's definitely possible, they don't use much memory. For grid graphs I wouldn't create one larger than 512*512 (or perhaps 1024*1024, but that's really high for a grid graph) so that's the limit there, fit that to a map with the size you want and check if the precision is ok.
     
  7. why789

    why789

    Joined:
    Sep 23, 2011
    Posts:
    184
    how about dynamic obstacles on the navmesh?
     
  8. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Not possible currently, I need to implement boolean operations on polygons first (or well, I have implemented that somewhat, but it's a O(n^2) algorithm and way too slow for practical use). You can use dynamic obstacles on a navmesh, but only triangles which were there from the beginning will have their walkability (or other values) changed, it won't create new better fitting triangles.
     
  9. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, so I set up a grid and an agent with a Seeker, AIFollow, Simple Smooth Modifier, and funnel modifier.
    Everything runs fine in the editor, but after I create a build for iOS and go to that scene, it crashes.

    It’s crashing when it creates a new graph:

    this is what I get in xCode:

    I turned off the agent just to eliminate it and it still crashes when it loads the scene on the device.
    This is happing in both scenes I'm using a graph.

    Here is Thread 1 from xCode:

    I'm using the Mono Debugger and a Exception was Caught:

    I'm using a Grid Graph, not sure what's going on, but any help would be appreciated.

    I want to buy the pro, but I need to make sure it will work first.
     
    Last edited: Feb 28, 2012
  10. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    It seems it crashes in the System.Guid.NewGuid function (which is a .Net function, not one I have written). Are you using bytecode-striping?
    Try disabling it, and check if it works.
    If GUID is the problem it seems like you (or me, since iPhone is a quite important platform), will have to write a replacement class for System.Guid.
     
  11. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    I was using "Use micro mscorlib Level 3 size reduction (includes reductions from Levels 1 and 2)."

    I'm creating a build with no stripping at all. It will take about 10 min (huge game)

    Replacement class for System.Guid?? I'm not sure how to do that!
     
  12. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    No problem, I know... sorta.
    Do you think you can try to create a class like this:
    Code (csharp):
    1.  
    2. #if UNITY_IPHONE
    3. namespace System {
    4.    public class Guid {
    5.    }
    6. }
    7. #endif
    8.  
    And check if that compiles ok when you build it (need to find out if it still thinks that the guid class exists or if I can just replace it like this).
     
  13. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, I tried it twice with no stripping and it crashes at the splash screen. The first time I chose append, the second time I chose "replace".

    So, I'm building it a third time with stripping turned back on.

    Then I will try that code above. Do I just put it at the top of one of your scripts or do I create a new one?

    Before it crashed at the scene, now it crashes at the splash screen
     
  14. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    You can put that code anywhere in your project. Create a new script or whatever. (though it has to be C#).
     
  15. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, here is my code:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. #if UNITY_IPHONE
    5.  
    6. namespace System {
    7.  
    8.    public class Guid {
    9.  
    10.    }
    11.  
    12. }
    13.  
    14. #endif
    15.  
    16.  
    17. public class GuidClassExtend : MonoBehaviour {
    18.  
    19.  
    20. }
    21.  
    but I get this error:


    Assets/AstarPathfindingEditor/Editor/AstarPathEditor.cs(1888,96): error CS0433: The imported type `System.Guid' is defined multiple times
     
  16. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Ok, do you get that error when in the editor and compiling, or when building the player and compiling?
     
  17. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    right after I hit "Save" in mono in the editor console.
     
  18. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Ah, I know

    change it to
    Code (csharp):
    1. #if !UNITY_EDITOR  UNITY_IPHONE
     
  19. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, that cleared the error, I'll run a build and see what happens,
     
  20. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Effectively it makes the code not included in the editor.
     
  21. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, I placed the script on a game object in my scene and I'm running a build.
     
  22. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Didn't work, still the same crash!
     
  23. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Okay, but the compiler didn't say anything? So it could compile the stuff?
     
  24. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
  25. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    I did get this yellow caution:


    Assets/Editor/PropertyEditor.cs(100,51): warning CS0618: `UnityEditor.EditorGUILayout.ObjectField(UnityEngine.Object, System.Type, params UnityEngine.GUILayoutOption[])' is obsolete: `Check the docs for the usage of the new parameter 'allowSceneObjects'.'

    I don't know if that's related at all
     
  26. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    That's great!

    It means I can write a replacement without modifying the original code.
    Just to make sure it actually works. Change to this:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. using System.Collections;
    5.  
    6.  
    7.  
    8. #if UNITY_IPHONE  !UNITY_EDITOR
    9.  
    10. namespace System {
    11.  
    12.    public struct Guid {
    13.  
    14.         public Guid NewGuid () {
    15.              System.Console.WriteLine ("BIG LETTERS SO IT CAN EASILY BE IDENTIFIED IN THE LOG!!!!");
    16.              return new Guid();
    17.         }
    18.    }
    19. }
    20. #endif
    21.  
    Hmm, now I saw the guid is a struct, so it might not work anyway. Try this and check the log for big letters.
     
  27. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    [EDIT] It should be public static Guid NewGuid ()
     
  28. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, I replaced the lines in the file, now in the editor I'm getting this:

    a yellow:


    The class defined in script file named 'GuidClassExtend' does not match the file name!

    Does that matter? What should the file name of the script be?
     
  29. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    That's your other class "GuidClassExtend' you added, remove it and it should go away.
    Also the other warning is not from my project, it's harmless anyway.
     
  30. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    The error came up when I removed:

    public class GuidClassExtend : MonoBehaviour {


    }

    So I added it back in at the bottom of the script, so it looks like this now:

    Code (csharp):
    1. using UnityEngine;
    2.  
    3.  
    4.  
    5. using System.Collections;
    6.  
    7.  
    8.  
    9.  
    10.  
    11.  
    12.  
    13. #if UNITY_IPHONE  !UNITY_EDITOR
    14.  
    15.  
    16.  
    17. namespace System {
    18.  
    19.  
    20.  
    21.    public struct Guid {
    22.  
    23.  
    24.  
    25.         public Guid NewGuid () {
    26.  
    27.              System.Console.WriteLine ("BIG LETTERS SO IT CAN EASILY BE IDENTIFIED IN THE LOG!!!!");
    28.  
    29.              return new Guid();
    30.  
    31.         }
    32.  
    33.    }
    34.  
    35. }
    36.  
    37. #endif
    38.  
    39. public class GuidClassExtend : MonoBehaviour {
    40.  
    41.  
    42. }
    43.  
     
  31. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Crap, I missed that. LOL!!

    Ok, so look this over and see if it's correct:

    Thanks:

    Code (csharp):
    1. using UnityEngine;
    2.  
    3.  
    4.  
    5. using System.Collections;
    6.  
    7.  
    8.  
    9.  
    10.  
    11.  
    12.  
    13. #if UNITY_IPHONE  !UNITY_EDITOR
    14.  
    15.  
    16.  
    17. namespace System {
    18.  
    19.  
    20.  
    21.   public static Guid NewGuid () {
    22.  
    23.  
    24.  
    25.         public Guid NewGuid () {
    26.  
    27.              System.Console.WriteLine ("BIG LETTERS SO IT CAN EASILY BE IDENTIFIED IN THE LOG!!!!");
    28.  
    29.              return new Guid();
    30.  
    31.         }
    32.  
    33.    }
    34.  
    35. }
    36.  
    37. #endif
    38.  
    39. public class GuidClassExtend : MonoBehaviour {
    40.  
    41. }
    I'm not sure if I put that change in the correct place
     
    Last edited: Feb 28, 2012
  32. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    No, the function should be static not the class.

    public class Guid {

    and

    public static Guid NewGuid ()
     
  33. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok,

    so change the "public struct Guid {"

    to

    public class Guid {

    and the

    public Guid NewGuid to
    public static Guid NewGuid ()

    Like this:


    Code (csharp):
    1. using UnityEngine;
    2.  
    3.  
    4.  
    5. using System.Collections;
    6.  
    7.  
    8.  
    9.  
    10.  
    11.  
    12.  
    13. #if UNITY_IPHONE  !UNITY_EDITOR
    14.  
    15.  
    16.  
    17. namespace System {
    18.  
    19.  
    20.  
    21.    public class Guid {
    22.  
    23.  
    24.  
    25.          public static Guid NewGuid () {
    26.  
    27.              System.Console.WriteLine ("BIG LETTERS SO IT CAN EASILY BE IDENTIFIED IN THE LOG!!!!");
    28.  
    29.              return new Guid();
    30.  
    31.         }
    32.  
    33.    }
    34.  
    35. }
    36.  
    37. #endif
    38.  
    39. public class GuidClassExtend : MonoBehaviour {
    40.  
    41. }
    42.  
     
  34. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Oh, forgot about the struct ;)
    Everything correct except change "class Guid {" to "struct Guid {"
     
  35. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    I ran it and it's still crashing, but it's not giving me anything in the mono debugger, nothing will pop up. So, I'm trying it in xCode to see what that gives me.

    I'm not sure where the log is on mono, last time I got that info, mono detected it and produced the results. I'll try again.
     
  36. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, this is what I get in xCode:


    Unhandled Exception: System.NullReferenceException: A null value was found where an object instance was required.
    at System.Guid.NewGuid () [0x00000] in <filename unknown>:0
    at Pathfinding.NavGraph..ctor () [0x00000] in <filename unknown>:0
    at Pathfinding.GridGraph..ctor () [0x00000] in <filename unknown>:0
     
  37. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Ok... that's probably alright... (structs should never be null... so the only thing which can be null is System.Console which I have a hard time believing...) Try to change System.Console.WriteLine to Debug.Log.
    There is progress at least :)
     
  38. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Also, this is not going to solve the problem, I'm just trying to figure out what kind of workarounds I can apply.
     
  39. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, so it did not crash this time YEAH!!!

    Here is the output:




    (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 34)

    Deserializing...

    (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 34)

    Creating Graph of type 'GridGraph'

    (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 34)

    Deserializing Error Encountered - Writing data to AstarData.data_backup:
    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: A null value was found where an object instance was required.
    at System.Guid.NewGuid () [0x00000] in <filename unknown>:0
    at Pathfinding.NavGraph..ctor () [0x00000] in <filename unknown>:0
    at Pathfinding.GridGraph..ctor () [0x00000] in <filename unknown>:0
    at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    --- End of inner exception stack trace ---
    at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
    at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
    at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
    at Pathfinding.AstarData.CreateGraph (System.Type type) [0x00000] in AstarData.cs:406
    at Pathfinding.AstarData.CreateGraph (System.String type) [0x00034] in AstarData.cs:396
    at Pathfinding.AstarData.DeserializeGraphsPart (Pathfinding.AstarSerializer serializer) [0x001b0] in AstarData.cs:266

    (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 34)

    Deserialization complete - Process took 163.39 ms

    (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 34)

    Scanning - Process took 4 ms to complete

    (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 34)
     
  40. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Nope, the error happened inside deserialization. I have put a try, catch block there to catch weird errors (such as this one).
    However, it doesn't output anything of those really big letters which I wanted. This is a but troublesome since I don't know if it is calling our code or the .Net code (which seems to have been excluded by Unity).
     
  41. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Try to set the _guid variable in Base.cs (in AstarPathfindingProject -> Generators) to null. It says in a comment above it that it isn't used. I think it is that piece of code which threw the exception last time.
     
  42. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Oh, and also. Do you have Fast or Stable (don't know the exact names) for execution set. I think that you can set in the player settings if it should handle exceptions or if it should just crash. Set it to the one which handles exceptions in any case.
     
  43. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, trying this now. I set it to handle exceptions earlier, I guess that's why it didn't crash. LOL
     
  44. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, how do I change the code? Like this?

    public System.Guid _guid = null;

    Update,

    That didn't work LOL!!

    I'm getting an editor warning with above code. I'm not sure how to set it to null
     
  45. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, I commented out the

    and ran a build, I got this yellow caution:

    public System.Guid _guid = System.Guid.NewGuid ();


    here is the xcode output:

    Ok, I removed my script that created the Guid class and it still runs. Looks like commenting out that one line worked. Do I need that line in when I buy the pro version and use a navgrid? That's want I really need this for. I want to have it auto create navgrids.

    Thanks,

    JL
     
    Last edited: Feb 28, 2012
  46. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Hey! No errors! Looks like that little piece of removed code did it!
    It will however be quite unstable if you try to create new graphs during runtime.
     
  47. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    That line of code was not used (if i can trust my own comments, i just hadnt gotten around to deleting it), you wont need it in pro.
     
  48. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Great, thanks so much for helping me with this.

    Ok, so my plan is to buy pro and use navgrids with all of my levels. From what you said a few days ago, that is the fastest. I want to build the graph then save it and load it at runtime so it will not have to scan on start of the scene.

    I tried that with a grid graph in the free version, but I'm not sure how to set it up. I got the script from your website on loading it.

    I checked "Cache startup" and then "generate cache", and then save to file. but when I it, it still seems to be creating a graph at start.
     
  49. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    If you check Cache startup and click generate cache (but you don't need to save it to a file). Then it will load from cache at start. At least if you use the latest A* version (in earlier versions only pro had the save nodes feature).
    It will say creating graph xxx at startup, but it won't say scanning graph.
     
  50. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, I got the pro version and I love it! Thanks,

    I do have a question.

    I'm using a Racast Graph and it's in a building with 2 floors, I have the graph all set up where it can route a path to the second floor. But when I have a agent with a target on the second floor, and the agent is on the first floor, it does not route the agent up to the second floor, it route the agent right below the target on the first floor.

    So, the agent just walks over on the first floor, to where the target is directly above him and stops. How can I get the agent to route a path to the second floor. The second floor has a collider and it's in the mask on the RacastGraph.