Download

Networking weapon fire sound.

So I’ve been trying to figure out how networking works, reading over the resources on the wiki and docs. From the First Person template provided when you first create a project, replication of object movement, projectiles and player movement works fine but I’m struggling to understand how to play the fire sound locally and also attached to the player for other clients.

I’m uncertain as to whether I should be using NetMulticast or not but it seems like it could be the right direction, although when attempting to use NetMulticast to play the fire sound it only plays on the listen server host.

In isolation, a NetMulticast isn’t a bad way to replicate a sound that is played from code that runs only on the server. I’m not sure why NetMulticast is not working when you try it: as long as its being called from the server on an actor that is replicating, the multicast should go through.

But, taking a step back, replicating individual ‘play sound’ events may not be the best long term approach. Rarely is a sound truly played in isolation. Usually it is part of some higher level game event which may produce other side effects. For example, you may actually want to play a sound, spawn a particle effect, and throw a message on the hud. Instead of replicating these three things individually, it would be better to replicate a single event which then implicitly fires off all the things.

So, rather than replicating a ‘PlaySound(FireSound)’ RPC, replicating a ‘Fire Weapon’ RPC would be better. That event could play a muzzle flash FX and a sound. You would still only want to do the actual damage calculation and health modifications on the server, but its fine to send the clients events that tell them to do all the necessary client side stuff.

Thanks Dave, that’s actually really helped me understand how the networking works. So am I correct in assuming that I’ll have to set the owning Actor on the server and replicate it to have the ‘Fire Weapon’ RPC correctly attached?