I created a dummy project to illustrate this, you can see in the video below how server and client behave when I move the actor and then simulate physics.
This all my character BP, I spawn and attach a dummy actor to my character and then press a button to drop the weapon server side. You can see there I detach the actor, move it in front and then simulate physics.
This is the dummy box I’m attached to the character, it has a static mesh component as the root component, it has the proper collision to simulate physics. It’s set to replicate and replicate movements.
Here’s the result playing as standalone, and playing as client. It looks like the SetActorLocation is not taking effect on client until later when the server corrects the location.
Is there something I’m not understanding or should I do it differently ?
The objective is: detach the actor, move it in front a few units and simulate physics.
Hey there @KaidoomDev! To preface this, I’m not a master of replication!
So here’s the fun part with replication for me. Since only the server is setting the location, it’s not telling the client to move the object there, it’s just telling the client after the fact it’s been moved by normal server positional updates.
I think since this teleport action is instantaneous, takes a second for the client to catch up. In cases like this, having the client do the same thing on their side simultaneously should yield very little popping if any. Which is why the multicast works to make this better, the client then also sets the actor location, then if it’s a bit off the server would compensate and adjust after the fact. In a low complexity environment this isn’t much of a problem.
If this is off, please someone correct me! I generally work on singleplayer games.
Thank you for answering.
I checked the Actor::OnRep_ReplicateMovement which is the RepNotify responsible for updating replicated movement, the issue seems to be if bRepPhysics and the location are replicated at the same time or bRepPhysics is replicated first then the new location will not be processed.
PostNetReceiveLocationAndRotation is called to update the location, I added an override to this function and added a log message and it did not log when I run the test, however when I removed the SetSimulate node and only set the location it did log.
I also noticed that PostNetReceiveLocationAndRotation is not called when correcting physics location on client, so it’s probably another function that only corrects based on difference between server and client.
Lastly I just wanted to confirm so I added this bad example to always update location and it did fix the issue.
So I think the solution is to do an unreliable multicast to force the location or handle the above function to detect when that happens and force the location once.
I didn’t know that! That just went in the notebook. I learn more from you every single time you post something!
In this case, I don’t see a problem with using a multicast and forcing it to update when it’s called. You’re only using it for the dropped items in this case right?
haha I’m glad you do, I also learn from your posts
I think this is the function that handles that, I added a log to it and it’s being called repeatedly during the simulation. The comment confirms it.
Gotcha! I don’t forsee any issues with this, and honestly can’t think of a better way to do it since this call has to be server sided initially anyway. If I get some time later I might see if I can formalize something like this and make it a snippet for the community, if that’s alright with you?