I’m at a bit of a loss with this issue.
I instantiate entity prefabs during runtime. They have a character controller, rigidbody, sprite renderer, animator, and a C# class for their AI/movement code.
I noticed when doing a build (release or development), I can’t instantiate more than 190 of them. If I try to instantiate 190 or 191 entities at once, it works fine. When I add one more than that, the build freezes indefinitely, requiring a force restart.
I’ve tried to reproduce it in a small, testing project and was unable to. There, despite still having a sprite renderer, character controller, animator, and all the same components, I was able to instantiate thousands without issue.
When I played around with it further, I made the following observations:
- It seems to be related to the sprite renderer or animator. With these never enabled, the instantiation works fine.
- Leaving the sprite renderer enabled wasn’t a problem if it didn’t have a sprite to render.
-Instantiating with them enabled but quickly disabling the sprite renderer/animator (within the same frame) did not cause problems.
-The freezing happened even without the animator when a sprite was set in the sprite renderer by default.
Note that it works fine in the editor always. This is only relevant to the build. And I can’t see it being a bug in my code if it works fine with a specific number of entities, but then freezes indefinitely when only one extra is added.
Beyond this problem, I get this situation where very much enlarged versions of the sprite images are flashing in the bottom-left corner of the screen for brief moments, only when several of the same instantiated entity share the screen.
Like the freezing bug, this one also only happens in builds. I wonder, given they both seem related to sprites, if they’re the same bug or related in some way.
Has anyone else had issues like this? Can’t seem to narrow it down enough to submit a bug report.