I’m trying to keep a constant, slow, stream of actors fed into my level.
They have functions tied to them.
The actors are destroyed when they fall to a certain Z.
So then the functions are no longer working even though there are plenty of actors still alive.
I’d like to keep 5 Target Actors alive at a time so I have a “compare to Int”. When one is spawned it should add 1 to “available Targets” variable. When it is destroyed it should subtract from “available targets”. But once one is detroyed this no longer works and no more are spawned since I guess its destroyed and needs to be alive to spawn itself.
I see that I may have gone about this wrong by having the actor spawn itself after the initial spawn essentially. But how would I go about recreating this better?
You need to keep the actor management separate from the actor themselves.
So put all the stuff about counting and spawning in a central BP that you drop in the level. And just take a look ( on a timer ) how many target actors you have.
Try to avoid using Tick fucntion as much as you can. You should focus your game to be event based in order to keep it optimized.
And, one more thing, please don’t use GetAllActorsOfClass, especially not in the game runtime (after world’s BeginPlay). You can create list of actors, or whatever you need, in your GameMode (offline game), or GameState (online game). GetAllActorsOfClass is not cheap at all.
Thanks @ClockworkOcean and @Everynone for coming to my rescue again.
Removed the Tick and setup a blueprint I called “BP_MANAGER”, it it now holding this function and a few others. I also have a function on a timer now.
Thanks @Bojann, I removed the kill actor tick and used the killzone instead. Worked Great.