Hey guys,
I have very big trouble with FPS drops in my game.
When “world” spawn 10 teleports, and all spawn one Enemy, FPS drop.
I don’t have any idea how to fix that… Teleport and Enemy have rigidbody.
I created where simple enemy model in Unity with animation.
This is just an unfortunate fact of life with unity, since it is single threaded, creation of new game objects is synchronous and blocking, so creating several objects in a single frame can and often will cause a lag spike.
I would suggest just trying to break up the work over several frames. So instantiate maybe just the teleporters on one frame (or X teleporters each frame until you have them all) then perhaps do a similar thing with the enemies, not spawning them all on the same frame.
Consider also that each time these objects instantiates it will initialize all of the scripts and components on them, so if you have some particularly heavy script costs when an object activates, consider trying to optimize them, this will be helped by using the profiler in unity to see where all the time is going during this lag event.