- Home /
My Spawner Spawns Forever until Unity Crashes
I have tried absolutely everything... eveeeeerything. I am still new to Unity and it's inner workings but from what I can find on the big wide internet... there isn't a reason my spawner is doing what it's doing which is just spawning indefinitely until Unity crashes.
this is my script... please I'm desperate here.
You need to show the code that trigger the On$$anonymous$$ailSorted event, probably that is run all the time...
Answer by madferretdd · Sep 22, 2020 at 11:03 AM
You could try taking it out of the update function into a void CheckMail() function then just call it in OnEnable() and in SpawnMail()…
Oh I finally fixed the solution in the wee hours of the night.
I simply removed the reference for the other script.
Instead, I had my prefab script which destroys the item. Then my spawner script that spawns a new item if there are 0 items in scene with a specific tag.
Answer by gillemp · Sep 22, 2020 at 01:25 PM
Have you checked that all the prefabs that you are using have the tag "mail"?
Why don't you try to save the spawned elements into a list and then checking that list size?
To be sure about the counting of spawning I would create a "manager" for the spawned objects. This manager could be singleton and you could spawn them using it. Instantly registering them in a list and checking the size of that list instead of searching for them.
Oh I finally fixed the solution in the wee hours of the night. I simply removed the reference for the other script. Instead, I had my prefab script which destroys the item. Then my spawner script that spawns a new item if there are 0 items in scene with a specific tag.
Your answer
![](https://koobas.hobune.stream/wayback/20220613012327im_/https://answers.unity.com/themes/thub/images/avi.jpg)