types of objects

types of obstacles

What I did in my game was to have a List of unused spawns in the spawner. The list starts off empty and when you need to spawn a new spawn, you take the first one in the list if it’s not empty, and create a new spawn() if it is empty.

The spawns have a script on them that detects when they’re no longer in the game. When this happens, they hide themselves, shut themselves off, and call their spawner with themselves as the parameter. The spawner then adds that spawn to the list of unused spawns.

When reviving a dead spawn instead of creating a new one, the spawner has to set the same details as when creating a new one (like the position and what animation it should play), but also has to make the spawn visible and reactivate it.

Without actually giving you the code itself, that’s really the best I can explain it. If you simply follow the steps listed above though, you should have a working recycling system in your spawner pretty easily. Good luck!