AI general optimization question

I’ve just started using the free version of your AI and i’ve got to say, it’s amazing. Went through the tutorial yesterday, got the AI to work in my simple TD game. The fps was quite low, even at 20 AI objects I was falling down to 50-60 fps. After changing how the distance was calculated with a sqr.magnitude, i’m able to run 100 AI moving in a big maze at around ~50-60 fps, which before was running at 5-10fps. My question is, are there any other optimizations that I can do with the AI system? what topics would you recommend to look at? Any general tips?

Thank you in advance.

1 Like

Sorry for the late answer.

Best tip: profile first!!
Also, what distance checks did you switch out?

Don’t use CharacterControllers, they are slow, just use transform.position and possibly a few raycasts. Use AIPath and not RichAI (if you are using one of them, AIPath is faster). Ideally you could write your own movement script which is more specific to your game and faster than AIPath. Especially if you have > 100 AIs.

Below are pro only features you could use:
For a TD game, most characters are moving towards a specific point, that’s really nice.
There is a FloodPath configured precisely for this purpose, but if you download the beta there is an even more awesome feature.

You would use this:
And you would place a single pivot point right where your targets are headed (or one for each target it there are not too many, if they are close to each other you can use one pivot point for multiple targets).
This will instantly boost your pathfinding performance by maybe 2-5 times.

The FloodPath will be faster if you have a specific target, but it is less flexible and requires you to do a bit more coding. The solution above takes under a minute to configure and works without a code change.

See flood path documentation: