Spawning ~100 projectiles at once

Hello there, I’m trying to work on shotgun mechanic where I spawn ~100 projectiles all at once, and I’m looking for some ideas on performance. Until now I’ve just been spawning the one projectile but now, I’m spawning anywhere between 1 and 100. I’ve changed my code to spawn 100 at once, and it seems like I’m having some problems. First of all, whenever I spawn 100 actors it stutters for a second. I’m guessing that’s because it doesn’t have the chance to finish the tick function. Second of all, when I replicate this it seems to cause some serious network lag. This is not entirely surprising, that’s a lot to replicate all at once.

If you take a look at the screenshot it gives a much better idea

I’ve tried a couple things. I’ve tried separating them out into components. The problem is that I have properties in blueprint, which can’t be determined in the constructor to initialize the components! I’ve tried disabling replication and spawning client/server versions. I’m not fond of this idea, and it did sort of work, but it still causes a huge hiccup when they all spawn at once.

I’m looking for some idea as to how I can possible to it so that they spawn without the crazy lag. Any help is appreciated. Thank you!

you should separate aesthetics from mechanics, and cut corners to save performance. you don’t need to constantly update replicated locations of deterministic cosmetic effects, you just need to call a spawn function on the client that uses the same spawn location and rotation from the server, and trust the server version of the simulation to score points. what the client sees is just cosmetic, and only needs to be updated when the server version changes course or hits something.

if you need to spawn this many similar things at once, you should probably be using a particle effect, instead of spawning actors. maybe your game would be just as fun, and more performant, if you treated this shotgun blast more like an area of effect blast, by expanding a sphere and checking for begin overlap. but instead of a sphere, like a bomb, you can model a low poly pie slice mesh, with its origin at the tip of the slice, and use a radius of 1. then you just scale that pie slice mesh to match the speed of the particle effect. this isn’t as precise as checking every bullet, but its way cheaper. this technique works best for short range shotguns or melee attacks, but depending on your game design, it might work.

so replicate as few things as possible. only the server needs to know the objective truth about the world, and clients only need to be informed when things change course from their predictable behavior. video game tech art is closer to magic tricks than physical particle simulators, so make use of big invisible hit boxes and vector math, to avoid spawning tons of separate physical objects. and if all else fails, change your design, use less projectiles, stagger their spawns, or just design a more interesting attack that is cheaper to make.

Little late, but thanks, this is sort of what I ended up doing. There is no replication going on at all for the projectiles now. I have a random stream that, when the player fires it sends a message to the server, which then sends a message to everyone, which spawns x number of projectiles randomly but, it’s the same across all clients with the random stream. works quite nicely.