I am creating a game where I need ALOT of units more specifically 200+
My question here is what can I do to optimize the pathfinding? if I do individual pathfinding using RichAI will the calculation of each individual unit crumble my PC? and if so is there a best practice when it comes to this amount of units on screen at the same time?
I personally haven’t done too much optimizations on my end.
But here are a few items you can have a look at.
First and foremost read this: https://arongranberg.com/astar/docs/optimization.html
Don’t forget about the links at the bottom of that page also.
Here are a few more personal suggestion:
- Don’t use any tags or penalty systems.
- I haven’t tried this but I’m sure it could bring some optimization: MultiTargetPath: https://arongranberg.com/astar/docs/multitargetpath.html This can calculate multiple paths at the same time for multiple agents with the same destination.
- Manually decide when agents recalculate their path, you could group multiple agents and offset the recalculation rate per group.
- Change how the update methods are called, I call my update less based on distance using https://docs.unity3d.com/Manual/CullingGroupAPI.html You can do a lot with cullinggroups like disabling animators, or even replacing your agent with a billboard particle.
Hope that helps!
If you need the highest performance, writing a custom movement script is the best. Alternatively you can take an existing movement script and strip out all the features that you do not use (for example if you don’t care about rigidbodies, there’s some code in the RichAI script that checks for rigidbody stuff that you can remove).