Hello, I’m doodling with Unity atm and working on a personal rts/moba style project. Currently I have gotten some basic functionalities to work - like being able to move/attack units, hostile units having AI and auto aggroing, etc.
I wanted to see how many units my game can handle, and I was kind of shocked that even with almost very little code - my game was dropping to 20~40 frames with roughly 400 units in the game. Some of them not even pathing, actually about 60~80% of them being idle and only the remainder being active.
I was seeking advice on how I can improve the performance of my game - maybe some more experienced individuals can share some knowledge and tips regarding this aspect. Currently all my textures are CPU instances, I’ve tried changing all of them to GPU instance, but I’m not quite sure if that did anything - I did not see any improvements, so I changed them back for the time being.
As for my AI code, it is a class with roughly about 200~300 lines that is tacked onto gameObjects. It uses the NavMeshAgent component offered by Unity to handle pathing. One of the things I’ve made sure to implement, is a timer like condition in the Update() so that the AI functions aren’t running every game tick. It’s at 0.125f seconds.
One question that comes to mind - is it better to have a one singularity instance member looping through all the unit as nodes in a list, or is it better to have each unit with it’s own class instance attached to the gameObject? Currently I have each class attached to the gameObject, but I can definitely rewrite the system to put them in a list. That brings a more general question about low timed loop functions, if there’s a lot of stuff to do in low periodic timer - is it better to store them all in a list or have them as separate class instances?
If you have any tips and tricks - please let me know! I would also love snippets :).
(P.S. - I have no debug messages turned on, so that probably isn’t it either. My CPU is kind of mediocre, but it can handle several hundred units in other RTS games with minimal frame drop).
