Greetings all,
I’m programming a game where a group of ai-controlled box-collider rigidbodies move to waypoints around on a blank terrain. Nothing fancy has been implemented as of yet, it is all very basic, with no effects etc.
This works fine if I have less than 6-7 rigidbodies, at around 50-60fps, but if I up the number to say 20, my frames per second drops off dramatically to around 20-30fps. With 40, my computer grinds to 3fps.
Clearly, I’m doing something wrong here with my methodology. What is the best way to control large groups of ai objects in a game in Unity?
Cheers all
What method are you using currently?
What are the requirements of your AI?
Sounds like you’ve got too much going on in your Update loops. Are you talking about the desktop here? Because Unity should handle that no problems.
Why don’t you post your Update loop and we can take a look. Since Update/FixedUpdate are running all the time, often moving stuff out of them or using a event based system rather than polling can have dramatic impact on performance.
What do you mean by an event based system? I am self-taught, so I’ve basically had to figure it out as I go along and many a time I’ve discovered a command or function that I didn’t even know existed that has solved my problems - this is probably one of those…!
It’s more a technique than a specific function. Event based instead of poll based means doing nothing until some event occurs instead of checking for something every loop.
I.e. want to see if I have hit something.
I could check each loop (in Update) to see if I am overlapping with the thing I want to hit.
or
I could attach a trigger collider and wait for the OnTriggerEnter event.
The first method is potentially doing something intensive (like a raycast) each frame.
The second method is doing nothing each frame.
That is just a simple example of course, but it’s worth looking at what you’re doing every frame and seeing if maybe you move it out using some kind of event.
Ah right, well I am use OnTriggerEnter for a few things, I’ll see what other events are knocking around for me to take advantage of - thanks mate!
Hav you read through the optimization guide? It probably will gif u some general idea on how to optimized your game.http://unity3d.com/support/documentation/ScriptReference/index.Performance_Optimization.html