- Home /
Why does my game lag horribly after 4 A.I. spawn?
Hello, I am making a zombie game where at night zombies spawn. I want at least 20 zombies but for some reason after 4 zombies my game lags horribly. I have a high end computer which plays Skyrim on Ultra with no lag. Why does this lag? Here is my code in javascript which spawns the enemy.
var enemyClone : GameObject = Instantiate(enemy, transform.position, Quaternion.identity);
I need to see the AI to give any answer to that. I mean that single line could be used to spawn 100 cubes with no scripts on them and that'd be no problem. There's nothing wrong WITH THAT LIN$$anonymous$$ If I had to guess with limited data that I have, your AI script on these objects is probably too complicated OR the geometry of those objects is too complex to render quickly; but either way, there's not enough info here for me to say much.
I have a bunch of scripts on my AI. $$anonymous$$ovement scripts, damage scripts, and player locator scripts
Thos scripts are what is slowing down Unity! Optimise them or live with less than 4 AI Spawning them doesn't slow Unity down at all, it's whats getting spawned thats allways the problem.
How do I optimize them? Would fitting them in 1 script do the job? Or just simplify each script?
Look up optimising, you need to make the AI less taxing on RA$$anonymous$$/CPU/GPU
Your answer
![](https://koobas.hobune.stream/wayback/20220613093026im_/https://answers.unity.com/themes/thub/images/avi.jpg)