I am not sure if this is the place to post this but I am having issues when I use Instantiate. I have been working on this game for a while and for a while when I used Instantiate to add an enemy to my game it worked perfectly. Now all of a sudden my game freezes whenever I use Instantiate. I have no idea why. I tried adapting an object pooling system when I Instantiate a fixed number right away and in the game just freezes when I hit play. I have a lot of code and I am not sure which code to show you. The only crazy thing that I am doing is that I am loading my enemy prefab from my Resources folder rather than using a public GameObject but like I said it worked perfectly up until like 3 or 4 days ago. Does anyone have any ideas?
Use the profiler to see what is causing the game to sit and spin. If it is your code, the profiler can be used to get pretty detailed down to exactly what in your code is taking so long.
When you say it freezes, do you mean that it locks up forever? Or it stalls for a second or two and then starts working again?
It it’s completely stuck, that tends to be the result of an endless loop, but it’s hard to say. Try attaching the Visual Studio debugger, and pausing while the game is locked up. That should (hopefully) stop at the point where it’s stuck. You might need to pause and result a few times before it stops at the right place.
But, if you have any while/for loops in the controller of the thing you’re instantiating, look into whether it’s possibly in an endless loop.
I gets stuck forever I have a couple for loops which instantiate and initialize the enemies I don’t have any while loops. Where would I get the visual studio debugger? By the way thank you for your response
Unity generally installs with Visual Studio Community. If you don’t have it, you can download it here: Visual Studio 2022 Community Edition – Download Latest Free Version
During the install process, it asks if you want to install any extra stuff. Make sure to choose Unity tools. Then, once it’s running, you can Attach to Unity (big button towards the top) to attach.