I’ve run into an unexpected performance issue:
i was trying to create a simple artificial life simulation (like so, just simpler: http://www.youtube.com/watch?v=SVoGKkzNXKk)
I have tried various approaches from particles and scripted gameobjects that replicate itself to array-crunching and pure text-based output. All in JavaScript. (figured: DrawCalls don’t seem to be the bottleneck).
Now all of these seem to hit a wall at around 400 active agents when my FPS drops below 10. (2.4 GHz Core2Duo, GeForce 8600).
So i was wondering if anyone knows a trick how to simulate, say 2000 actors with 20 iterations per second similar to the video above.
(So far the actors are all independent and do not interact. All they do is move randomly, replicate and die based on a timer)
Any ideas much appreciated.
make the AI simpler if you intend to have 40’000 iterations per second or ensure that you are on a mac pro not an imac / mbp with its mobile CPU which is cut on the calculation end
If you make a webplayer from your test, I can give it a go here on my Core 2 Duo E6600 @ 2x 3ghz + GTX 280 + vista64 @ 8GB RAM
For reference checks on large amounts of AI: get supreme commander. all scripts are done in LUA and can be accessed by anyone for modding
Start by making sure no dynamic typing is going on (as this will get Unity’s Javascript slow). If you put #pragma strict at the top of your scripts, you will get a compile error in all places where this happens.
Then go watch Joe’s talk on performance:
http://unity3d.com/support/resources/unite-presentations/performance-optimization
so the solution for my script was as simple as changing
for (...) {
x = tranform.position;
}
into
cachedPos = tranform.position;
for (...) {
x = cachedPos;
}
great video.