I have a large open world area where it only makes sense to spawn all enemies from places where you enter and exit the open world.
The problem is, the open world is the persistent level, so if you go in and out of areas several times, enemies are spawn, spawn, spawned. This causes the game to slow significantly both in PIE, and in builds.
To combat this, i have a collision BP that covers the entire world open map. It hovers above it and i have triggers set to change the transform of the collision when you exit the persistent level. The BP casts to parent enemy BP, and destroys them, then it transforms back up above the persistent level.
This works, but i get sometimes hundreds of “accessed none” errors, and I can’t think of a better way. Given that it does what it is intended to do, how terrible would it be to ignore these errors? Also, if someone has a suggestion for a better method, i am all ears.
I usually use is valid for accessed none, but there are a lot of spawned enemies, so what would i plug into the is valid? Just a reference to parent enemy promoted to var?
I am streaming all of the sub levels and the persistent level is open world. Ill play around a bit with the is valid but im not completely sure what the is valid is checking. Thank you for your comment!
Are you using some sort of dummy actors placed in the level which spawn the actual pawns? Sounds that way since you say they keep spawning over and over any time you get close.
If this is the case, try storing a reference to the spawned pawns as a var on the spawner, then in its event EndPlay, destroy the referenced actors. Dunno if you’re using World Partition in UE5 or World Composition in UE 4, but either way, the EndPlay event on editor placed actors should be triggered when their level is streamed out.
if you will spawn actors often in the level is suggested you just
spawn a big stash at the beginning and store those actors in some
bulk array, then you can just implement some activation/desactivation
of your actors and move to some ‘activeActors’ array and then move them
back to your ‘availableActorsforUsing’ array.
This way you dont spawn/destroy all the time.
Spawn and destroy is very expesive.
Thanks for the reply. No i am not using world comp because it was extremely buggy for me. It is a different world deving for mobile. It works fine in other projects but not in this one. Ive just opted to stream all sub levels and just have a well optimized open world partition level.
I havent used end play to destroy actors. Would you mind an elaboration?
From what i gather in your post, i store a variable for all spawned enemies which come from the spawn actor node. After that, i would have a collision box that when my play over laps, it would then call the end play in the spawners. Or would it be best to have the end play in my parent enemy? Literally all of my enemies currently have the same parent.
It is super expensive for me. I will look into this, but it would probably require me to start from scratch with all enemies in all sub-levels. It might have to wait for another project.
I forgot to answer, yes. I am using blank BPs that i place all around the map. when i overlap a collision spawn box, it will get all of these BPs and have them spawn the respective actors.
i then have another collision box, and when overlapped, it moves the enemy destroy box over the open world and destroys all enemies. this is what that box does:
Is it bad to have all of these? I feel like accessed none is worse than garbage. this just goes to the garbage collector and there is no worry right? Honestly, the way it is setup right now is working as intended, despite all of that garbage. i have so much to do in this project
EndPlay event on spawner should be called automatically when the level streams out, so you shouldn’t need to call it from a trigger. And, yea, whenever spawner spawns a pawn, add the reurn value from the spawn actor node to a variable.
Then on spawner’s EndPlay, check if pawn is valid (and any other conditions you want to compare), then destroy it. Naturally, you’d do this in a foreach loop if you have an array of actors as the reference variable.
The main part of my spawn function looks like this:
PawnDied event is called via interface from the pawn when it dies so they’ll respawn. Ignore the set text bit, that’s just for a debug label floating above spawnpoint.
The follower bool is a bit of a hacky way to make bodyguards/pets not despawn when the spawner streams out.