First Name
Last Name
Confirm Password
Please validate your account by clicking the link in your email
Resend Validation Email

Pathfinding in Unity ECS! (Epic Performance!)


Let's take our Unity DOTS Pathfinding and apply it to Unity ECS so we have Entities roaming around calculating their path.

Download Project Files
Post Comment


Code Monkey
Here's some Pathfinding with Unity ECS that can go up to 50,000 units!
Dan MacDonald
Love these, keep it up!
Dav Tam
Bought the bundle and look forward to keep on supporting you in the near future, you are really good at articulating DOTS.
Code Monkey
@Dav Tam Awesome! Thanks!
Stijn Kievit
Very nice video! I tried to apply this in my own project, but I have a really hard time providing the paths back to my "normal" object based scripts and mono behaviours. Do you have any suggestions on how I can provide a list of vectors / grid positions back to a mono behaviour after the job is complete. Thanks!
Code Monkey
I covered using this mixed with Game Objects here https://www.youtube.com/watch?v=XomlTHitAug
Blake guyan
Hey, When i convert over the script for my pathfinding i get a whole raft of errors stating i need an object reference to a non static field.
I realise that its because you converted the function calculatePath to a static, i just dont understand why i am getting it and you didnt?
Blake guyan
OK Mystery solved.. i had a rogue closing bracket after the Dispose commands that locked off the functions being called from the main function which was the root of the error! also, anyone coming from the last tutorial might run into a weird pathfinding error caused by the grid size being too small! you need to always make sure your grid size is LARGER than the coordinates you are trying to pathfind to, if you find you are getting some odd results, thats why!
M. Nenad
Awesome video as always! But even with your files I could't reproduce the project in a version that is lying flat on the ground (y swapped with z-axis). Somehow the grid that is used for pathfinding doesn't match the grid from the Grid class (visible in scene)... I cannot get the grid position recalculated into world position properly. Did someone experience similar problems? Thx in advance
Please show us how you did the animation with seperate meshes for your characters
Code Monkey
I cover how my animation system works here https://www.youtube.com/watch?v=11c9rWRotJ8
Simeon Vasilev
Hello, first thank you for the tutorials that you are making, they are really useful. I just have one question - I am not able to find MeshUtils in Utils package that you provided, are you able to share it or just to mention, what is the purpose of GetQuaternionEuler method, it should return float based on input float(I am a little bit confused here). Thanks in advance!
Stijn Kievit
Hi Code Money, great content! It is very informative and help me out a lot! I have one question, in my own project I try to overlay a pathfinding grid over an existing tile-based Gameworld and do a an physics overlap collider check for every cell in the grid. I was wondering if there is a better solution to this. Thank you! Keep up the great work!
Code Monkey
If you do it very rarely then yes that is a very nice and easy approach.
It only becomes an issue if you constantly update your Pathfinding map, if so then it would be best to keep a separate grid just holding a boolean and you update that manually when you modify the map.
1LS Gaming
this is some pretty amazing stuff! Can entities be enabled/disabled for pools? I was thinking about making a small simple DOTS rts based on your tutorials
Tyler Buth
Just an FYI, I am literally following along with some of this code and a few times you've done massive deletes and reformatting and you sped up the code so that it was really really hard to see what you actually did. I can figure it out looking at before and after but it makes it pretty confusing. An example is around 11:30. You added pathPositionBuffer then you perhaps make a delete and comment out some code but it goes very fast so it's hard to tell.
Cody King
Any idea if it scales well for larger maps? I guess you could use the hierarchical nodes to reduce some of the blunt force path finding.
Code Monkey
Sure it scales very well and continues to be very fast in a large map. But regardless of how fast it is at some point you need to use multiple maps, can't have the entirety of Skyrim in a single Pathfinding map.
Martin Grof
Hi. If you're interested, you can write to a BufferFromEnitity in a IJobParallelFor.
When there are changes in the scenario while the unit is still in movement, it simply passes through the new obstacle.
By changing the unit's behavior to redo the pathfinding when there is a change in the scenario, that was solved, but then a problem became obvious:
When the unit tries to find a path and is not in the center of a node, the unit goes back to its center, and that could allow exploitation from the player.

A simple fix for it was to remove the initial node from the path in the calculatePath method, and that made pathfinding retries seamless.
I plan to make a free path tower defense game, and this is going to be very useful. Thank you very much.
Code Monkey
Yup normally that's what I do, calculate the path again if something changes or just over time and always ignore the first path position.
Apparently blizzard used ECS for overwatch, primarily to reduce coupling/complexity (amazing video, includes a description of their netcode: https://www.youtube.com/watch?v=W3aieHjyNvw). They barely mentioned performance at all during the talk. Performance aside, do you find that the ECS programming model likely leads to good, understandable architecture, or do you find that having state on a component potentially shared between several systems is error prone?
Code Monkey
I believe ECS helps you write better code since it forces you to separate Data from Logic. So by default you can't possibly end up with a class that is thousands of lines long with complex interactions between data and their logic.
I mean you can still write bad code of course but I believe the limitations imposed by ECS will guide you to better code.
The one potential pitfall is if you use the same component type in lots of systems, at that point it becomes tricky to remember how the data in that component is behaving. The solution for that is using smaller components with a single responsibility.
Nikita Kazakov
This is some wizardry
Fantastic material as always. I have a small problem though, after converting to entity my unit becomes invisible, it still is in the debugger, but apparently is not visible. And yes, an RTS game in DOTS would be amazing! Please do.
Code Monkey
Do you have the Hybrid Renderer package installed?
@Code Monkey No, I completely forgot about it! It is that for sure. Thanks
Nándor Bacsó
What's the difference between this and the DOTS video?
Code Monkey
This one applies that Pathfinding code to the Entity Component System so you can add components to request a path and calculate it
Soma Cruz
oh is this can be helpful for 3d rts?
Code Monkey
Its especially useful for RTS where you have tons of units and complex maps
haitham mahmoud
can u please make tutorial how to make 3D dynamic roads (path) or floors like tycoon games
Paul Robinson
Hi CM. I'm in the process of putting a game onto the play store, have you any idea what I name the pricing template, is it the game name or something else. There is nothing to suggest what it should be and don't want to screw up :(. Nice vid by the way, as usual :)
noah games
Hey, I am here from a older video of yours. the graph one and I need help. I am copying exactly as you do but it aint working
Code Monkey
You can download the project files from the website
noah games
@Code Monkey I know I have compared and everything but my tooltip just wont go to where my mouse. it displays the correct size but not the right info or spot