No announcement yet.

Replicating multicast sounds with lag

  • Filter
  • Time
  • Show
Clear All
new posts

    Replicating multicast sounds with lag

    So I've come to a bridge that I can't seem to pass. Probably a very simple solution but I can't seem to find it. The problem is I'm attempting to play a gunshot sound which is replicated to all clients without server delay in the case of lag. I'm using the pktlag command to induce lag into the project and delay client1(around 300ms).

    Whats happening so far:
    -Client1 shoots weapon
    -Server 300ms later detects client1's decision to fire
    -Client1 and all other clients hear nothing until the server detects the input 300ms after client1 technically shoots

    What I would like to happen:
    -Client1 shoots weapon
    -Client1 hears gunshot sound
    -Server 300ms later detects client1's decision to fire
    -All other clients hear replicated gunshot sound

    I feel it's quite simple but replication seems to be a real pain right now.

    You are at the heart of the replication / lag problem mitigation.

    If you look tutorials about this on the internet, it will tell you that you can't get rid of the lag delay, you just have to hide it somewhere.

    "Hiding it", what does it mean? In your case, it means exactly what you are trying to do: make it so you don't perceive a delay when you shoot, because the visuals (animations, sounds and FX) are played instantly instead of waiting for the Server validation.

    A proper way to do it in your case would be to have 6 functions:

    "InputPressed" is triggered after a left mouse button click, it runs "TriggerShootVisual" then it runs "ServerUseWeapon"

    "UseWeapon" runs "TriggerShootVisual" if not locally controlled, then it asks for authority, if it has it it runs "TriggerShootGameplay"

    "ServerUseWeapon" triggers "MulticastUseWeapon"

    "MulticastUseWeapon" triggers "UseWeapon"

    Note: I have talked about a listen server setup (your server is one of the player), in case you're working with a dedicated server you just have to build your logic without triggering any cosmetic event on the server.
    [Released] Multiplayer Combat Editor
    A-RPG Sacred Swords
    Auto-Chess Live Development
    Youtube Tutorials


      Thank you Yun-Kun, but wouldn't this technically replicate the sound on the client's machine during the multicast as well therefor the lagged player would hear their shot twice? Maybe I'm just not understanding because the logic for playing my sound is done inside the weapon's blueprint instead of the player's pawn(sorry I left that out).

      I found a solution though, very similar to the one you provided.
      -The client shoots their weapon and immediately fires a client side "play sound" function inside their held weapon blueprint through an interface function on their held weapon reference
      -The client passes their character reference through the interface function to be used later
      -The server detects the client's input
      -The server passes to all other clients
      -The sound is only played on clients where the character reference DOES NOT match that of the passed characters(the client that fired the weapon)

      This works flawlessly in my case and the lagged player only hears the gun shot once(immediately) and all other players hear the gunshot immediately following the lag delay.
      Attached Files