A* Pathfinding Project

Dynamic Grid Object on AI


Hello everyone,

we have setup the scene with the path finding system (2D) and the enemies got their AILerp, Seeker and DestinationSetter components. Now we wanted to add the DynamicGridObstacle component on each but the enemies start to behave very weird. They are “jumping” around while walking.
Is our setup wrong or did we missunderstand how the DynamicGridObstacle is supposed to be used?

Looking forward to any help,
thanks a lot in advance!



You can’t make agents themselves obstacles as that will make the agents try to avoid themselves as they are constantly updating the graph to make the ground under them unwalkable.

Maybe you want to have a look at this page instead? http://arongranberg.com/astar/docs/turnbased.html also take a look at the example scene called ‘Turnbased’.


Thank you very much for the reply!
I’ve changed the setup now and enemies are not running on top of each other anymore but now I’ve noticed big lags in some situations. I wonder if this is just because I’m using something wrong from the API or if it’s because of the selector list you wrote about in the tutorial that should keep as less obstacles as possible for performance reasons.

So what I did now was to keep track of each ground and air unit in the enemy spawner with two separated lists. When I’m setting up the new enemy instance I’m adding it to either of the lists and pass a copy of that list to the enemy which removes it self again, otherwise I would get the same problem I had earlier again.
So far it works fine, they start walking one after each other, but then once they find like a bottle neck in the map it starts getting super laggy which didn’t happen with the AiLerp and AiSeeker system I was using previously.

I would really appreciate some hints what might be wrong.



Those selectors are indeed designed for quite small use cases. You shouldn’t put hundreds of items in there (even 10s will reduce performance a bit). If you need that many it might be necessary to rework the code to use a hash set or something similar (which is a lot slower for small selectors, but faster for large ones).

You could possibly create a custom ITraversalProvider which checks your game rules more efficiently (e.g. is this unit also a flying unit like me and is it not myself).

Note that these methods are intended for turn based games. Not because of performance issues but because they only plan based on where the other units are right now, not where they will be in the future. If you use it for a game where all units move at the same time you might get bad results.

Does the profiler say anything interesting when it starts to lag?