Why does my object spawner stop working after a minute and 40 seconds

I created a spawning object that spawns a actor when there is no actor present. The object is destroyed on use causing the spawner to reset. Theoretically this should continue working forever but for some reason the object stops respawning after 1 minute and 40 seconds every time.


Have you the value “Inicial Life Span” differet to 0?

1 Like

If IntialLifeSpan is OK like DomusLudus mentioned, You may want to try this code.
(I edited your screen shot in Photoshop to illustrate)

Create a CustomEvent and name it SpawnSushi and add it to the BeginPlay to spawn the first fish (you can add a delay if want to if you want the first one to spawn a bit after the level loads). Then set the Spawner variable for all the fish types to self.
(Like this you don’t need to run a Tick and I assume the Delay was to prevent multiple spawns)

Also you have to Reset the MutiGate or it will be closed and does nothing after the first spawn batch.

Get the Spawner variable in all the fish types (assuming you set them all up the same as the Tuna). Call the SpawnSushi Event and then destroy the old fish)

I also wanted to mention if your goal is to spawn 1 random sushi, you should use “Switch on Int”. The way the MultiGate working in your code is it exits the random StartIndex and then you set the SushiPresent bool to true which stops the tick. When the SushiPresent is set false it allows the tick through and it gets a new random number for the StartIndex. If the Multigate already exited that index it will go to the next index that hasn’t been exited yet. Example: it exited random indices 1,4,8,9 and the next is a repeat of random int 8, it will skip indices 8 and 9 and go to index 10 which hasn’t been exited yet. Once all 14 outputs have been exited it closes the gate which then needs a reset to spawn anymore sushi (or if Loop is selected, no Reset is required). This is why after about 1 min 40 sec its stops spawning.

Here is a log of the MultiGate running a test.


image

This is unrelated to any possible solution, but in the spirit of suggestions…

  • Seems like the switch is intended for weighted selection? You can create a function for that:

  • Could be good to have an array of soft class references assuming the spawned classes have a common parent even if it’s Actor class:

  • IMO the spawned class shouldnt include the spawner. Actors can know when another actor has been destroyed by binding to OnDestroyed:

Then you end up with something that should be easier to iterate upon:

WeightedSpawner

Hope it helps.

Thank you, this worked