- Home /
Game runs fine first time but lags when stopped and started in editor.
I am having a problem when running my game in the Unity Editor. The first time I run my game it will perform as expected. When I stop and start the game using the 'play' button within the Unity Editor it will run extremely slowly. If I close the Unity application using the 'X' window button and restart the application the game will again run OK the first time and then lag if restarted using the 'play' button.
I am working on optimizing the performance of my enemy objects. To test their performance I spawn 50 enemies one at a time with 0.5 seconds in between each spawn.
The first time I run the game it will gradually slow down to 30-40 FPS* as the 50 enemies are added. Once all the enemies are added the frame rate will stay stable.
The second time I run the game (after stopping and starting with the 'play' button) the game will very quickly begin to lag as enemies are added. When it reaches 25 enemies the frame rate will be <1 FPS.
If I exit the Unity application in Windows and start it again then the game will run fine again the first time and lag when restarted.
There are no errors or warnings in the console.
My game makes use of the DontDestroyOnLoad() method in order to create a static enemy pool. Enemies are created in the first scene of the game and re-used rather than created and destroyed. I used the 'Persistent Singleton' pattern for this pool, which is described here: http://unitypatterns.com/singletons/
I have posted this problem on Reddit and tried some troubleshooting already. You can read the thread here for more information: http://www.reddit.com/r/Unity3D/comments/2q6o2b/poor_performance_after_restarting_game_in_editor/
The problem has occurred in both Unity 4.5 and 4.6. I have tested the project on another computer and encountered the same problem. I don't have any third party editor plug-ins or scripts.
I suspect some data is persisting between runs in the editor. Does anyone know of anything that could cause this behaviour?
I don't know if it's relevant but sometimes it will slow to 30 FPS and sometimes (on different days) it will only slow to 50 FPS with no known change in background applications running.
I wish somebody would have answered you on this. I have this same issue.
Answer by YoungDeveloper · Apr 26, 2016 at 08:51 AM
I've had similar problems with unity editor performance. The bottleneck was the running profiler. Or i should say the reason was poor development machine.
Your answer
![](https://koobas.hobune.stream/wayback/20220613175518im_/https://answers.unity.com/themes/thub/images/avi.jpg)