Projectile replication from UE5 FPS template

Hello,

I am very new to this and have been watching some guided tutorials on setting up a multiplayer FPS game. I am using the UE5 FPS template and am attempting to replicate projectiles so that the client projectiles show up on the server.

The UE5 template is set up with BP_FirstPersonCharacter, BP_FirstPersonProjectile and BP_Rifle where the character blueprints simply call the rifle blueprints as an “item”. I am not seeing this blueprint setup in any tutorials/guides I have found.

The most success I have had is following the solution here Using FPS Template, the Projectile is replicated from server to client the Clients aren't replicated back. However, adding those components to the BP-FirstPersonCharacter blueprint only allows the projectiles to shoot in the initial X direction that the weapon is set up at once the gun is picked up (you do not spawn with a gun in the FPS template), and the audio does not play. The gun behaves correctly from the server end so I did not want to mess with the other blueprints. Here’s what the base template looks like:




I really appreciate any help with this!

This template doesn’t seem fit for replication.

I don’t have UE5 atm so I took UE4 FPS template and made a basic replicated fire loop. Hopefully you can grasp the various aspect and adapt to your project.

The UE4 template doesn’t have a rifle class, so I put everything in character. It sounds definitely better to have such logic in rifle class, but it shouldn’t make a big difference overall.


So let’s start with input - we start a fire loop locally and tell server to start firing too.
The local fire loop will not spawn any projectiles, it will only play fire effects for the local player so there’s no apparent round-trip delay between click and visually firing.


We enter fire loop on both local client and server (same machine if we are listen server host btw). There’s a bit of logic to prevent entering loop twice etc, we are maintaining fixed minimum interval between shots - so you can spam clicks or hold LMB and it won’t fire faster than minimum interval.
When a shot is due (FireShot called), the server spawns projectile. If we are the local client (who just clicked), only simulate fire effects for now.


Next we spawn projectile (on server). This is a slightly modified version of the FPS template function that was provided. Do not use FirstPersonCamera as it won’t work on servers for non-host players. Use GetActorEyesViewPoint instead. I’m not familiar with MotionControllers so I left the stuff as-is (might not work).
Also we pass ourselves as instigator/owner of the projectile.


Enable replication on projectile. Use projectile replication to tell all other clients to play fire effects for the player who just fired.


Finally, play fire effects (sound, anims, muzzle flash…)


Note that there are many ways to implement a replicated fire loop. Here I’m spawning the projectile on server, and let the server replicate projectile to clients. And I’m using projectile replication as a “multicast” so I don’t have to use any multicast event.

An alternative would be to not replicate the projectile, and instead use a multicast event, and let everyone spawn his own local projectile.

If the fire loop is very fast, it would be more adapted to replicate only startfire/stopfire all the way to remote clients, and let everyone manage their own fire loop. This way you save bandwidth by not replicating every single shot.

Again it all depends on what your project needs, there’s no one-fits-all solution, which is also why it’s not easy to find full blown multiplayer templates.

Thank you so much! I’ll try and fit this into the existing blueprint but the vibe I’m getting is that I may need to just redo the firing logic into something more scalable.

Thanks again!

The firing client should be firing locally (client fakey), then RPC’ing the server to either multicast or spawn a replicated shot. This adds responsiveness similar to client-side prediction. Otherwise when clients shoot there’s a full ping delay between input and action. Anything over 60ms becomes extremely noticeable. Avg MP ping is around 80ms, with highs around 180ms.

I always test with a 500ms ping.

1 Like