Replicate the Transform of BP Actor



As you can see in the code:

  • There are a series of calculations running off Event Tick to move the BP (a train) along a spline (this works as it should but is quite complex to make sure each wheel remains on the track and yet still turn the corners etc.)
  • The problem is that in multiplayer, the train is in two places at once depending on when the client joins so i need to replicate the transform of the bp.
  • The BP itself has Replicates and Replicate Movement checked.
  • I have tried a variety of things including, making all the variables that make the equation replicated, using RPC events etc.
  • My latest attempts have been to simply add a Switch has authority node and run the calculations on the host and then at the end Get the World Transform of the main meshes and set them as Replicated variables… then off the remote switch the client basically skips the calculations and Sets the World Transform of each mesh using the replicated variable.
  • This does not work either, before this I also attempted to make the variables Rep Notify and have the logic inside there but that also didn’t work.
  • I assumed replicating the movement of an actor bp from host to client would be relatively easy but I am really struggling. Can anyone see why or point me in a better direction?

Any replication gurus around? Ive come to a total stand still now

You should look into network prediction. A train should be pretty predicable without having to update the entire transform on every network tick.

I honestly cant understand why none of the methods are replicating though. Perhaps im missing a key concept in how the client access a replicated variable. I also tried the take recorder which seemed a great and cheap solution, it perfectly caught the trains movemnets and can loop the playback and there is even a checkbox for replicate playback, so that both host and client see the same moment of the sequence. Alas, it wasnt in sync and became quite buggy

With “Replicate Movement” checked you only have set the Actor location on the server and the client will update on every network update but it will not be smooth on the client unless if you add some prediction between the network updates and smooth out corrections. You can find plugins on the marketplace that helps with network smoothing as it can be a tricky subject.

Well for the time being it doesnt move on the client side at all with any of my attempts, i agree with you that i was expecting it to as simple as checking replicates and the host would pass the variables to the client but no dice :unamused:

Have you confirmed that “Switch has Authority” returns “Remote” on the clients?

Hmmm i added a print string, for the host the values are getting set and change on the tick. For the client all the values return 0 - so the client is getting the code via remote… but the variable isnt passing or being replicated? Even though the variables are checked as replicated… currently looking for an online tutorial where someone moves an actor via replication to see where im going wrong

What do you mean by this? Are you visibly seeing 2 duplicate meshes or just that the server has different location data than the client?

Just that the server’s location is different than the client, sorry i should have clarified since we are discussing replication

Im wondering if it matters that im testing this via standalone, then using my subsystem to join multiplayer… my game is already a working multiplayer on steam. It works for everything else i test so it probably doesnt matter but just in case
Edit: Also, wondering if some of this should be in the lvlbp or the character bp?

OKAY: weird update, so I cahanged the code to this:

  • I am making sure that everything has a switch has authority node applied so only the host (server) is controlling the train.
  • I have replicates and replicates movement checked.
  • I am also now spawning the BP_Train in the world via the level blueprint with a switch has authority node aswell.

What i’ve found out is that the client cant see the train, but it can ride it (but the client only gets notified of their position, being where the train is, when they jump) The client can also see spiders that have landed on top of the train, but cant see the train so its just spiders in the air moving along the track but the host confirms that they are just on top of the train.

Takeaway is: the train seems to be replicating, to some extent… but the actual BP_Train is invisible for the client. Maybe I need to take away the Switch Has Authority node in the level bp where the train is spawned, I’m not sure :question:

Edit: I removed the Switch Has Authority node in the level bp, to my surprise (at this stage) the client saw the train, there seemed to be a little lag in location, it seemed to pull up at the train stop first for the host, followed by the clients train (this could also be the time difference in when the clients game loads) will try a few more times to clarify

Edit: So, they definitely arrive at different times, the host sees the train arrive and then the client sees its version of the train arrive 2 seconds later. They both board the train in its stopped position but since the host is ahead… on the clients screen the host is on the invisible train ahead of the clients train, the host however, sees the client next to them. Totally out of sync, I’m going to post a video to show whats happening more clearly

Here is a video that should be much more informative about the issue:

(Ignore the print string down the left side, perks of plugins)
Any other questions, please ask!

Is it because I’m running off event tick? Does that mean the client’s train position is tied to their fps??

As was noted by Garner earlier, you really should look into network prediction in the long term: the client should be able to move the train along that spline and only adjust it when the server location differs. Then you just need to get the initial location when you join, and begin predicting the location from that initial point.

(I mention this because it may be worth trying to get that done NOW rather than trying to get this working as-it-stands, only to turn around and rip all the code right back out to do it with actual prediction.)

As for your current situation, it’s really going to be difficult for any of us to see what the issue is without more detail.

A couple of questions I would ask:

  • When you say the clients can’t see the train, do you mean the train is visible somewhere but not moving (e.g. is stuck at the original spawn in location), or that the train is just not visible anywhere, at all?
  • If you print the actual actor location in the tick (as in Get Actor Location), what do you see on the clients? Do the values change at all?
  • What is this train? By which I mean, is this a generic Pawn using PawnMovementComponent? Did you make the train a Character and it’s using the CharacterMovementComponent? Things like that.

Really, the more precise information you can provide, the easier it’s going to be for someone to help.

Hi, I figured this would be the case so I posted a video showing all the code and exactly what visual inconsistencies I’m seeing - hopefully that helps

For your specific questions:

  1. I’ve had all 3 scenarios in various attempts to replicate the train, currently I believe the train is visible to the host and client but both see it in different locations (i.e. they have their own copies doing their own thing, not adhering to replication)
  2. when I did this, they didn’t change at all, but the replication method has been adjusted since then, I think when I used the switch has authority and only let the server spawn and do the code with the replicates and replicates movement checked, the train wasn’t spawning for the client
  3. The train is an actor blueprint
    (the video should showcase all of this much better)

Ideally i think it would be best if i could find a way of replicating the sequence I made with the take recorder

I think i have it almost fixed. I am now spawning the BP_Train from the character with a switch has authority (server only) instead of spawning it from the level blueprint.

I have also checked component replicates on all of the components inside the BP_Train (which itself has replicates and replicate movement checked, and also always relevant.

All blueprint logic to move the train (via event tick) happens with a switch has authority (server only)

What im seeing now is that the client sees 2 trains, one of which is replicated (only its a good bit lower on the z axis for some reason)

Any thoughts on fixing it further?

I admit, what I’d try to do at this point is make a fresh mostly-empty project and try to do fundamentally the same thing within that project.

If the problem still occurs there, you know it’s something in specifically that approach (and you have a simple project you can throw up on Google Drive or whatever for others to help you with); if the problem does not occur in an isolated fresh project, then you know there’s probably something going on more generally that’s complicating the situation in your real game.

Okay - here is a fresh third person template with the train in it: TrainTestSimple.zip - Google Drive

You can see the issue i’m having first hand, when a client is involved, multiple trains spawn at different transforms.

The third person character spawns the train and all other logic is located in BP_Train.

I think I’ve found the right way to spawn it so both the client and the server only see 1 train that is replicated:

However, I’m still perplexed as to why the client’s train is roughly -1000 on the z axis…
I also don’t understand logically why the server event needs to be called from the remote switch for it to spawn correctly