Using Unity Spring Joint Component with Two Rigidbodies Causes Desync
General Unity version: Unity 6 (6000.0.48f1) Fish-Networking version: 4.6.8R (Pro) Discord link: https://discord.com/channels/424284635074134018/1034477094731784302/1375842921865285703 (Others have asked similar questions about joints but I haven't seen any conclusive answers about it)
Description When using a spring joint component on two objects with rigidbody prediction enabled, the objects desync. I have tried a variety of set ups but nothing has yielded correct results.
Here are some things I tried...
Set Up Like the Prediction Demo: The rigidbody with the spring is a network object, with the other rigidbody as a child. The rigidbody with the spring does the replicate/simulate of the other rigidbody. The rigidbody prediction demo uses a set up like this for hinge joints, but I think the desync does not occur in the demo because the 'wheels' in the demo follow the body of the vehicle's position spatially.
Demo Set Up but Other Rigidbody also has Prediction Enabled: Same as above but the second object also has a NetworkObject component. The connectedBody falls as if no spring is connected. This occurs even if I set the connectedBody every frame.
Both Rigidbodies are Predicted Separately: I tried not simulating and reconciling the rigidbodies together but this did not fix the issue. The connectedBody falls as if no spring is connected. This occurs even if I set the connectedBody every frame.
Manually Adding Spring Forces with currentForce/currentTorque: I tried manually adding the spring forces to the PredictedRigidbody object in replicate but this did not sync the objects either. Below is a snippet of the prediction script.
I have a unitypackage which shows this behavior, but I can't upload it here.
Replication Steps to reproduce the behavior:
- Create a rigidbody, add a NetworkObject component and enabled rigidbody prediction.
- Create a second object for the visuals, and set up a NetworkTickSmoother for it to use
- Repeat step 1-2 for a second rigidbody
- Add a spring joint component to the first, set the connected body to the second rigidbody
- Create a basic prediction script for the rigidbodies individually (simply simulate and reconcile the rigidbody)
- Play and see the objects desync
Expected behavior From my understanding the objects should synchronize correctly even with the spring joint attached. The spring behavior is uncontrolled, adding reactive forces to the rigidbodies. So I am not sure why they are unable to be synchronized.
Spring join values cannot have their properties fully reset, which is required by CSP for accurate re-simulation. This is unfortunately a Unity limitation.