I’ll be honest, I have no idea how to use the micro profiler, so I will use the scrip profiler.
This is me spawning in 100 basic enemies, that fire a bullet every second, for about 10 seconds.
Certain things like .Chatted are due to the spawning commands being controlled by chat.
I haven’t changed the animations to run client sided yet. but that would also improve performance.
Running is connected with the animation controller, to fix this just change the run context on the animate script to client.
Delayedthreads is actually the enemy class handler, which also loads the loop that controls the enemy AI. due the fact that enemy AI skips pathfinding calculations if the target is directly visible, the memory cost was quite low. I managed to lower this even further by only making the targetting loop run every few frames instead of every frame.
Waiting scripts is the bullet handler. Since the bullets have travel time and bullet drop, you could expect it to be quite expensive. I’ve tried to resolve this by only making it update 24 fps and only doing dot product checks every significant change in angle (10 degrees). This could also be mitigated by lowering the amount of functions it has. currently bullets can do a lot of things.
Now we have the big hitters, Stepped and heartbeat.
Stepped is the update loop for the target update, and align orientation changes. It runs significantly more often than the pathfinding loop, because the loop is updates more frequently it has a high memory cost. for the fact AI is able to shoot at a different target, than it is pathfinding to. Funnily enough, it is actually the raycasts that cost the most memory for this function, clearly for checking visibility. A way to reduce memory costs on this is to use the same target and calculation for nearby AI sacrificing accuracy. Which I will skip because of the drawbacks.
Heartbeat is also the bullet scripts, and has the exact same reasons for the high memory cost. there isn’t a way to really fix this, other than using a Pool of bullets instead of instancing every one.
this is a screenshot showing the high memory costs of moving the bullet and Hit detection. This could be reduced by making bullets update even less, or changing to a single raycast. but this would make the game less fun.
for anyone else looking for a optimization for pathfinding, I do not recommend using a grouping system, as merging and other things take significant memory.
Instead opt for a method where if a person requires pathfinding, it will search for other AI within radius a single time to skip pathfinding.
As for the parallel / multithreaded thing, I am too inexperienced to know how to do this. I will inform myself, but currently all update loops are task.spawned.
This was also mainly a memory optimization thing, any network optimizations would also be highly appreciated.
Thank you for reading. any other optimization suggestions are very welcomed.