Networked DetachFromActor resets AActor position

I’ve encoutered a strange behavior when detaching an Actor from another when both are replicated.

I reproduced this behavior in an empty 3rd person project doing the following:

Linetrace from the camera to screen center and attach the hit object to the character using a server call :

When attaching the object everything works fine, but when I detach it it’s position is reset to Vector(0, 0, 0) on client only. Weird thing is that if I move my (client) character ON the object, the character is teleported to Zero until he leaves the object.

It is worth mentionning that the object is a simple StaticMesh with no physic simulation.

Is this an engine bug? Am I doing something wrong?

Hello oristal,

I attempted reproducing the issue you’ve reporting but I’m not seeing any abnormal results. I’ll go through how I set mine up to make sure that there isn’t anything we’re doing different. I did use the First Person template instead as doing line traces w/ the first person is just easier to aim in a lot of cases.

  1. Created a project based off the First Person template
  2. In the First Person Blueprint, I placed the nodes as shown in the picture below.
  3. I selected a static mesh in the level and ensured that it was set to “Static Mesh Replicate Movement”
  4. I set the number of players to 2, selected “New Editor Window” and then triggered the line trace to hit that Static Mesh from step 3
  5. The static mesh followed my transform and detached after the 4 second delay. The client saw all of the same behavior.

I made a few improvisations as I don’t know how you set up your start/end point for the line trace and I’m also not sure how you were calling ServerDetach. Also, it’s better to use IsValid when checking to see if a hit result actor is valid.

Please give this setup a try and see if it works for you and/or point out anything I did differently.

Hello Matthew, thanks for your reply.

I copied your blueprint and kept my server attach & detach since you didn’t seem to change that. What happens when I test it is that only the server sees the object moving, so I created a blueprint from one of the cubes in the scene and set it to be replicated.

This being done, the object followed on both the server and the client, and the bug occured when the object was detached.

Can you provide some input on this? Is there something I’m doing wrong?

I’m gonna see if I can figure out what may be causing the difference but in the meantime, here’s a copy of the project I put together. Can you make sure that this works for you?

In the project I sent, the cube that is sitting infront of the server when play starts is replicating. When the cube is attached to the Server or Client and moved around, both the Server and Client see the movement and when the cube detaches, it stops where it was at the time on both the Server and the Client. Are you not seeing this same behavior in that project?

Thanks for sending your project. Like I said, the cube’s movement is only visible to the server since it’s position is not replicated. The bug I’m having occurs by making the cube replicated

My bad, I didn’t pay attention to this particular cube. So it is actually working in your project, as expected, and the problem I had was that “Replicate Movement” was false - setting it to true fixed the problem.

I don’t fully understand the difference between Replicates and Replicate Movement. Does Replicates only toggles on the replication of custom variables/RPC?

Thanks a lot for your help

That is correct. The replication of the “Holded Object” variable in your blueprint won’t actually affect the mesh at all. This variable is only storing a reference to that Static Mesh actor, not the asset itself. This variable also doesn’t need to be replicated as the Attach function (where it is created) and the Detach function (where it is used and cleared) are both called on the server.

Replicates movement is a setting directly on the Static Mesh actor itself and will cause it to replicate across to clients.

One easy way to look at this from a networking perspective is that the client doesn’t need to know that the static mesh is attached to anything (unless you also need to stop the client from attaching that mesh to itself while the server has it attached), it only needs to know that it is moving.

Thanks for clarifying this :slight_smile:

Facing the same issue. Attaching the object on the server, the item is moving on the client, even with ReplicatesMovement=false. The only issue is the Detach, as it sets the attached actor to (0,0,0) on the client, as the OP mentioned.

Using ReplicatesMovement=True seems to be an overdose, as the object is moving already when attached. This causes precission issues for us as well, as the object transform is then replicated with a max of two decimal numbers.

I see it as an issue that the actor transform is set to (0,0,0) on the clients after Detach that should be looked into.

If the value is being edited on the server and the movement isn’t being replicated, that means that the movement values will never change on the client if the server is the only one affecting its movement. You can test this using the project I provided for the user above where it works correctly.

Thats what I would assume to happen as well. But if the transform of the actor on the client side is not touched with ReplicatesMovement=False, how come the actor on the client side is set to (0,0,0) after detach on the server?

I’ve noticed something even more odd when testing this further. If in PIE, using 2 players to test the networking, and you use Eject (F8) after the detach occurs, the cube moves to 0, 0, 0 on the Server’s end as well. When printing the location on tick from inside the cube itself, the server seems to be the one out of date and isn’t seeing it at 0,0,0, even though the World Outliner says as such. I’ve entered a JIRA report for this which you can find here: UE-44288. The description goes a bit more in depth on what I ran into testing this. Thank you for continuing to push back on this, or I may not of noticed this behavior.

Thanks Matthew, really appreciated :wink:

This issue is still present in UE 4.18 and we spent several days to figure out what was going on. Eventually we narrowed the issue down to detaching and found this thread. We ended up replicating the actor location from the server at the moment of detaching to all clients and set their actor locations right after detaching.

Faced the same problem. Did a bunch of tests to determine how the problem displays. It’s weird. Calling AttachToActor on the server fully replicates the change to the client, even with ReplicateMovement=false, but when you call DetachFromActor the following things happen:

  • The child actor still shows as attached to its parent on the client.
  • However, the child actor no longer follows the parent around, as if it was indeed detached.
  • If you called detach using KeepRelative, the client-side child will only update its world transform if ReplicateMovement is True. Otherwise it will behave as if it was detached using KeepWorld.
  • If you call detach using KeepWorld, the client-side child will be positioned at it’s server-side detach world position multiplied by 2, regardless of ReplicateMovement’s value.

The only way to get around this is to use an RPC or OnRep to call DetachFromActor on the client.

I attached a 4.19 project that demonstrates the problem: networkdetach.. Make sure to tick the “Run Dedicated Server” box. You can view the server-side simulation by pressing simulate instead of play.

Are you talking about ChildActorComponent when saying ChildActor? I gave up using them completely. Had tons of issues with them.

No, it’s just a separate actor that is attached at run time to another actor. For example, a character picking up a box from the ground and carrying it to another location.