No announcement yet.

Is this the proper way to replicate from client to other clients? (through the server)

  • Filter
  • Time
  • Show
Clear All
new posts

    Is this the proper way to replicate from client to other clients? (through the server)

    (photo 1) Button press -> Run on server function -> switch authority (is this used right?) -> multicast function -> spawn replicated actor.

    Testing it out with 3 players, the spawned actor is visible to the server, and clients.

    I'm a ue4 noob trying to learn it as accurately as possible, but can't find many good tutorials. All help is appreciated. Thanks!

    (photo 2) Expanding from this, trying to make a replicated projectile. I am having issues replicating the direction the spawned projectile follows. The projectile appears to the server and clients, and when casting from the client, everything works fine, but when casting from the server the projectile direction is not replicated back to the clients. Can anyone shed light on why this would happen? Thanks again!
    Last edited by Sociopath C-137; 04-03-2018, 02:47 AM.

    Spawning a projectile is usually done like this.
    1. The Client calls a RunOnServer event that has two inputs (projectile spawn location and velocity). Note that RunOnServer can only be called from actors that the client currently own (PlayerController, Possessed Pawn, Actors owned by the Possessed Pawn etc.)
    2. The Server now spawns the projectile with the vectors received from the Client (Location and velocity) and apply it to the Projectile. Note that the Projectile Actor needs to be Replicated and Replicate Movement.
    3. The replication kicks in and spawns the Projectile for all clients including the client that started this.

    So in your example you need to add location and velocity inputs to the "RunOnServerEvent".
    You can remove "SwitchHasAuthority" node as it is redundant. This never runs on a client so "Remote" is never used.
    You also don't need to Multicast if you enable replication on the actor you spawn in. You are spawning unique actors on each client instead of letting the server spawn one actor and "clone/replicate" it to the clients. The difference between the unique actor and the clone is important with synchronizing and when passing references between players. With unique actors you would have unique references however the cloned actors would all share the same reference.
    Another way to look at it is that the projectiles are not synchronized by the server but the server just tells the clients to spawn their own projectile locally. Whatever happens then is out of sync. with the other clients.
    Last edited by GarnerP57; 04-04-2018, 07:20 AM.