First up projectiles in multiplayer should not be replicated. You have each Proxy of the shooter do their own thing. Server should only replicate relevant data. Keep the network footprint as low as possible.
- Client fires its own local projectile. Simple hit detection, A/V FX etc.
- RPC the server to shoot.
- Server determines its own values and fires it for authority. Dmg hit detection etc.
- Multicast to SIM proxies passing the servers values.
- Sims fire the shot, A/V FX
- On Server hit, Multicast the loc, impact normal for SIMS and Owner to apply decals etc.
If you are using dynamic data, store it in a Data Table. The weapon class should grab the data and setup a struct (config).
Note :: The data passed from client to server (Srv Fire event) is only used for anti-cheat measures. It cannot be trusted. The Authoritative Proxy Fire
functionality does its own calculation for projectile trajectory.
If you want your projectiles dormant do the following.
- Disable Collision by default
- Auto Activate Off
- Simulation Disabled
Initializing the projectile
Key is updating the root component.
I use Object Pooled projectiles. Each Proxy (Autonomous & Authority) has its own dedicated Pool. I use an Actor Component that’s added at runtime and attached to the character. It spawns N number of projectiles, makes them dormant and attaches them to itself.
Sim Proxies use a global pool that’s created on each client.
When the weapon needs a projectile it requests one from the Bullet Pool component. Production version of this would utilize BP Interface calls vs hard referencing the component.
Bullet Config provides the teleport location (Muzzle), the Aim velocity, Lifespan and Range for the projectile. My projectiles have a set life span that’s based on their max shooting range. The life span value controls no hit shots returning to the pool when they have reached their max range. This reduces wasted resources… shooting clouds etc.
If you go this route you’ll need to bind Event On Projectile Stop. This will give you the means to clear any active timers etc.
When Anything has the projectile “Stop Simulating” We need to clear timers on any running logic. e.g. (lifespan etc).