Download

Actor Component Replication?

Hi guys!

I was delving into the wacky world of replication this week and hit a brick wall. I attempted to make a simple asteroids-esque shooter. All was well – the ship flys around and can fire little bullets … and all of it replicates fine. I then thought to myself: what if I had more than one gun, and have them rotate? I decided to add a few scene components to my ship and have them rotate based on a button press. No matter how hard I try I can not get the scene components to replicate. I can see it fine on the active client, but all other clients and server do not see the additional component-based guns moving. Is is possible to replicate an actor’s components? What is the real way to rotate parts of actors over a network?

I’m not sure about whats the real way, but unless there is specific replication behavior by default for components (probably not judging from your experiences) I would tackle it like any networked property: make replicated rotation variables for each component in the blueprint and whenever those change, apply them to the components both server-side and client-side.

So what I would do, in steps, for one gun:

  • Create a float GunYaw in your ship blueprint, make it RepNotify to make it replicated plus have an event handler for that
  • Implement OnRep_GunYaw to set your gun component’s yaw :D, no need to check network authority since the rotation needs to happen on both client and server anyway

Now, when setting rotation on the (listen) server, that should replicate to clients automatically and generate OnRep_GunYaw events client-side. Whats left is enabling clients to set their own gun yaw. Create a function that sets the yaw and set its Replication to Run on Server. When a client calls it, the server will actually execute it so again its replicated to all clients. Very straightforward but hope it helps. :smiley: