I am creating a wave based game as a learning project and use the “GetAllActorsOfClass” quite often. Unfortunately, if I don’t destroy the actors immediately after they are killed, it clogs my arrays and breaks the waves. I’ll try to explain to the best of my abilities, but I apologize in advance if I do a terrible job.
When a enemy dies, is there a way to change their type from actor to something else so that the GetAllActorsOfClass don’t see them? Whats the best way to go about this?
I’d like to keep the zombies visible and in the game so they can finish their death animation and then get destroyed, but as stated earlier, if I don’t destroy them as soon as they die, they are still technically counted as being alive.
I can explain more if need be,
Thanks!
Solution is to not use GetAllActorsOfClass at all, it’s quite heavy operation and it should be used as last resort if you have no other way to get actor references.
Insted you should add things to array when they are spawning and remove things from array when they killed (or whatever case you want), make actor send information to game mode (or wherever you have array) that it got killed or create event dispatcher that that class can register to (if oyu use level blueprint… but you really should do those things in game mode)
Other more quick solution is to have alive bool on actor and check that bool on any operation that suppose to be done on alive actor.
Ahh, Sounds easy enough, I’ll see what I can throw together and get back to you on that. Appreciate the advice!
Played around with that for a bit, so far its working perfect and has solved a few other issues I’ve been having. Appreciate the help!