How many AI Agents can Unity handle?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Brackeys I love your fps videos, you should maybe do some on enemy AI or active ragdolling

👍︎︎ 7 👤︎︎ u/Legorobotdude 📅︎︎ Mar 06 2018 🗫︎ replies

/u/brackeys any chance you could do a video on soft body physics? Only tutorials I find online are 2-3 years old and use the cloth method (which I think has been turned obsolete with the recent versions of Unity or has it?).

👍︎︎ 6 👤︎︎ u/Nielscorn 📅︎︎ Mar 06 2018 🗫︎ replies

I think you need to deploy the game to some platform and then run it in natively compiled mode to really take advantage of cpu instancing.

👍︎︎ 2 👤︎︎ u/dershodan 📅︎︎ Mar 06 2018 🗫︎ replies

Does this use the new Job system? I'm guessing not, I wonder how does it compare.

Just to clarify I mean the navmesh agents will use the new job system internally when it's released IIRC

👍︎︎ 2 👤︎︎ u/tagoth 📅︎︎ Mar 06 2018 🗫︎ replies

Thanks really great video. Surprised that Unity AI performed so well

👍︎︎ 3 👤︎︎ u/Nate4020 📅︎︎ Mar 06 2018 🗫︎ replies

The performance will go down a lot if they use a bigger level. A small level like this, would be pointless to have 5000 units anyways.

👍︎︎ 1 👤︎︎ u/Sky_HDMI 📅︎︎ Mar 06 2018 🗫︎ replies

I enjoyed this video. Showing the testing/optimization process was a great idea.

👍︎︎ 1 👤︎︎ u/[deleted] 📅︎︎ Mar 07 2018 🗫︎ replies
Captions
I think one of the coolest things in computer Programming is AI in particular AI that can be taught how to navigate and move around a 3d world I love playing around with path finding and setting up challenges for my little agents to solve in this video I'll be putting nudity's building AI solution to the test Let's see how it does So first I set out to build a maze for my testing to take placing after having looked at a bunch of different maze layouts I decided to go with a classic a traditional pac-man level after finishing my model in blender I set up a basic nav mesh using the new nav mesh tools which are available on github I then created a few agents with Standard settings as well as a simple script to control them all that did was to tell the agents to move to the same location On the other side of the maze using the shortest possible path to no surprise the test ran smooth However because of the grid like nature of the maze some agents could run straight through So quickly modified the level to avoid this now it was time to start adding in more agents Here's a test with just over 200 still everything was smooth But I found it hard to keep track of each Agents position so tried adding random colors to make them different from each other from looking at it I noticed a few things first the agents tend to clump together It seems that even though each of the agents are said to Continuously look for better paths the queue up instead of altering their route Which ultimately slows them down second it looked to me like the agents in the back was first to reach their destination Where's the agents in the front took a while to get going to confirm this? I colored each row differently and just as I thought the yellow agents in the back were much faster But they also seemed to start first it looked like for some reason the agents were starting one-by-one from the back to the front a quick look at the documentation provided an explanation for this behavior When setting an agent's destination that agent will start calculating a path in the background Once a path is found the agent will start moving so the agents were probably moving one by one because the navmesh System only calculates so many paths at once to confirm this I wrote a quick script That would update the color of each agent depending on its current path Status and indeed the agents would turn green and start moving as soon as a path was no longer Now of course I wanted to add more agents But as soon as I got near 400 things started to slow down so I opened up the profiler to try and find the culprit and to my surprise 75 percent of CPU usage was currently being spent on rendering while actually Updating the AI was only taking around 6% to make the agents render more effectively I gave them all the same material and enable GPU instancing I also made sure to disable vsync under the graphic settings and voila CPU overhead went from over 60 milliseconds to only 6 Next I wanted to make all the agents start at the same time to do this I wrote a custom script that would loop over all the agents and calculate a path for each one then once all agents had a valid path I would apply them all at once the result was a smooth simulation of 400 agents But that wasn't enough I wanted more so I expanded the maze and bumped it up to a thousand then 5000 at this point my computer was starting to slow down But before moving on I wanted to try making some modifications to the maze to see how the agents would react So tried adding a wall with a hole in the center I also tried adding a secondary hole to the side as expected to split the army into Those close to the side and those closer to the center now of course 5,000 agents are plenty to do lots of testing with but as I always try to tell people When they want to get into game development the most important thing is to have fun So I made the maze even bigger I also downloaded a framerate counter from the asset store and started tweaking settings to see if anything which make this simulation run smoother I created this spreadsheet to keep track of my findings as expected all settings related to baking the navmesh had no effect on runtime performance So I quickly moved on to the 18 component itself here tried messing around with a bunch of settings But the only thing that really had an impact was obstacle avoidance Turning this off of course meant that the agents wouldn't avoid each other, but it did improve my framerate by about 40% I also tried the different obstacle avoidance qualities But was surprised to see that the different was no more than a couple of frames at this point I just wanted to squeeze as much performance out of unity as possible so I tried Configuring rendering settings and even playing around with custom path findings illusions such as a star I was impressed to find out that unit is built in navmesh tools were still the fastest way to go however I will say that this might just be due to my limited knowledge of a star finally by building the game I managed to get the simulation running at 27 FPS and so it was time Time for ten thousand a I agents of course the simulation wasn't smooth In fact even as a standalone build it was only running at around 10 frames per second But still it was wonderful to witness this swarm of computer-controlled robots Mindlessly moving through the maze now I decided that 10000 might finally be enough, but that doesn't mean that wasn't room for more fun So I created an army then an army of cacti Finally, I thought what would be more suiting to end the day than hundreds of wild running horses I know how about hundreds of wild running horses riding towards the sunset? Perfect Thanks of the awesome patreon supporters who donated in February and a special, thanks to encode We trust Patrick McKinley Diego kike Frank Tristan town donggyun, Murphy Oh infinity PPR yo Rio myrrh and soft tune sighs mom eat turkeys Kirk face on Murphy beard or die DoubleTap 45 James P J delay Superman the great John ProGuard Dennis Sullivan Jason Latino Alex wicked ski beyond Photo Club Sweetland swell enough gin Sasha hafsteinn Sunni Arabs and Gregory Pierce James Rogers Robert Boone Durman Rob fan and Erasmus You guys Rock
Info
Channel: Brackeys
Views: 1,608,294
Rating: undefined out of 5
Keywords: brackeys, unity, unity3d, model, texture, models, learn, game, development, develop, games, programming, coding, C#, asset, assets, navmesh, AI, pathfinding, AI pathfinding, NavMesh, agents, test, crash, break, maximum, stress test, limit, how, many, bots, AI's, handle, support, maze, fun
Id: G9Otw12OUvE
Channel Id: undefined
Length: 6min 17sec (377 seconds)
Published: Sun Mar 04 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.