# SetSimulatePhysics produces different results in multiplayer

**URL:** <https://forums.unrealengine.com/t/setsimulatephysics-produces-different-results-in-multiplayer/374678>\
**Category:** Multiplayer & Networking\
**Tags:** Replication, attachment, unreal-engine, Multiplayer, question\
**Created:** [October 27, 2016, 10:42pm UTC](https://forums.unrealengine.com/t/setsimulatephysics-produces-different-results-in-multiplayer/374678 "2016-10-27T22:42:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rob422lou](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rob422lou/32/88719_2.png) [@rob422lou](https://forums.unrealengine.com/u/rob422lou)\
**Post date:** [October 27, 2016, 10:42pm UTC](https://forums.unrealengine.com/t/setsimulatephysics-produces-different-results-in-multiplayer/374678/1 "2016-10-27T22:42:43Z")

</div>

I’m trying to AttachTo() multiple physics simulating objects in multiplayer. I’ve run into an issue. If SimulatePhysics is false, and then you attach objects together, that attachment will replicate. If you then enable physics on the root attachment, they should behave as 1 physics simulating welded object.

The issue is that only works correctly in singleplayer or on the server. Clients however have 2 replicated variables with OnRep calls that break the attachment as soon as SetSimulatePhysics(true) is called on the parent attachment. OnRep\_AttachmentReplication() and OnRep\_ReplicatedMovement(), found in Actor.cpp and SceneComponent.cpp, are called for any child objects that have an attachment. In these replicated variables are values and function calls that tell the client that the AttachParent is now null and should DetachFrom() anything.

The inconsistency in behavior between the server and the client leads me to believe it’s a bug. Here’s an album of images in how you can replicate this behavior using blueprints: [http://imgur.com/a/HE0MZ](http://imgur.com/a/HE0MZ)

---

<div class="post-metadata">

**Author:** ![rob422lou](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rob422lou/32/88719_2.png) [@rob422lou](https://forums.unrealengine.com/u/rob422lou)\
**Post date:** [October 28, 2016, 3:15pm UTC](https://forums.unrealengine.com/t/setsimulatephysics-produces-different-results-in-multiplayer/374678/2 "2016-10-28T15:15:38Z")

</div>

I think I narrowed down what’s going on. In Actor.cpp in PreReplication the server sets AttachmentReplication.AttachParent = nullptr, which is a replicated value. The client then detaches based on that new information in OnRep\_AttachmentReplication found in Actor.cpp, a function the server does not run.

After the server sets that value to nullptr it runs a function called GatherCurrentMovement(), which sets AttachmentReplication.AttachParent = nullptr again, and then updates another replicated variable called ReplicatedMovement, which tells the client that the “child” object is simulating physics. But at this point on the client it’s no longer a child. So on the client 2 objects will start simulating physics independent of each other. The objects on the server will remain attached to each other however, as no DetachFrom() call is ever made.

---

<div class="post-metadata">

**Author:** ![Sean\_Flint](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sean\_Flint](https://forums.unrealengine.com/u/Sean_Flint)\
**Post date:** [November 7, 2016, 3:55pm UTC](https://forums.unrealengine.com/t/setsimulatephysics-produces-different-results-in-multiplayer/374678/3 "2016-11-07T15:55:28Z")

</div>

Hello,

Apologies for the delay. I was working through your screenshots and came across the Parent Actor variable in your last screenshot for your pawn logic.

Where is the variable coming from, what is its type and what is its default value? It’s possible I’m overlooking something but I just wanted to double-check.

Thanks

---

<div class="post-metadata">

**Author:** ![rob422lou](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rob422lou/32/88719_2.png) [@rob422lou](https://forums.unrealengine.com/u/rob422lou)\
**Post date:** [November 7, 2016, 4:08pm UTC](https://forums.unrealengine.com/t/setsimulatephysics-produces-different-results-in-multiplayer/374678/4 "2016-11-07T16:08:45Z")

</div>

The type is StaticMeshComponent. The default value is nullptr, it’s populated from the static mesh component called “cube” in BP\_Cube when the trace after the ‘R’ event hits one of the BP\_Cubes I spawn in the level. Thanks for looking into this!

---

<div class="post-metadata">

**Author:** ![Sean\_Flint](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sean\_Flint](https://forums.unrealengine.com/u/Sean_Flint)\
**Post date:** [November 8, 2016, 2:52pm UTC](https://forums.unrealengine.com/t/setsimulatephysics-produces-different-results-in-multiplayer/374678/5 "2016-11-08T14:52:24Z")

</div>

Thanks for the information. After some further investigation, I’m seeing a similar issue to what you’re experiencing. However, mine is a bit more erratic, meaning that I’m seeing the meshes be placed in varied locations around the map rather than just remaining suspended in the air.

However, in terms of the main issue that you’re having, it’s important to keep in mind that once you SetSimulatePhysics() to true on an object, it immediately detaches from its parent because physics simulation takes place in world space.

Have you given this a shot in 4.14 just to see if the behavior is the same? On my end, I’m seeing the objects stay welded, but the physics are a bit out of whack. Replicating physics is a challenging task, and is typically handled through other means such as updating the transform of the actors on the client on tick, just as an example.

---

<div class="post-metadata">

**Author:** ![rob422lou](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rob422lou/32/88719_2.png) [@rob422lou](https://forums.unrealengine.com/u/rob422lou)\
**Post date:** [November 8, 2016, 8:24pm UTC](https://forums.unrealengine.com/t/setsimulatephysics-produces-different-results-in-multiplayer/374678/6 "2016-11-08T20:24:59Z")

</div>

If you’re getting objects jumping around make sure your AttachTo rules are set to ‘Keep World’, as that’s not the default. I ended up having to override OnRep\_AttachmentReplication and OnRep\_ReplicatedMovement to make my own replicated attachment implementation. I will try it on 4.14 though, thanks!

---

<div class="post-metadata">

**Author:** ![Sean\_Flint](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sean\_Flint](https://forums.unrealengine.com/u/Sean_Flint)\
**Post date:** [November 8, 2016, 8:27pm UTC](https://forums.unrealengine.com/t/setsimulatephysics-produces-different-results-in-multiplayer/374678/7 "2016-11-08T20:27:49Z")

</div>

Did you get it working like you wanted to? If so, it would be great if you could provide your method for other users to reference if they run into the same issue.

Let me know if you need further assistance.

---

<div class="post-metadata">

**Author:** ![Sean\_Flint](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sean\_Flint](https://forums.unrealengine.com/u/Sean_Flint)\
**Post date:** [November 14, 2016, 1:56pm UTC](https://forums.unrealengine.com/t/setsimulatephysics-produces-different-results-in-multiplayer/374678/8 "2016-11-14T13:56:41Z")

</div>

Hello,

I am marking this topic as resolved for tracking purposes, as we have not heard from you in a few days. If this issue persists, feel free to respond to this thread. For any new issues, please create a new Answerhub topic.

Have a great day
