Skip to content

Commit bd738b3

Browse files
chore: update rigidbody deprecations (#3199)
* update Changing RigidBody2D kinematic checks to account for deprecation of isKinematic. * update Adding changelog
1 parent cefecf2 commit bd738b3

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1212

1313
### Fixed
1414

15+
- Fixed issue where `NetworkRigidBody2D` was still using the deprecated `isKinematic` property in Unity versions 2022.3 and newer. (#3199)
1516
- Fixed issue where an exception was thrown when calling `NetworkManager.Shutdown` after calling `UnityTransport.Shutdown`. (#3118)
1617

1718
### Changed

com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ private void SetupRigidBody()
5252
// Turn off physics for the rigid body until spawned, otherwise
5353
// clients can run fixed update before the first full
5454
// NetworkTransform update
55-
m_Rigidbody.isKinematic = true;
55+
SetIsKinematic(true);
56+
}
57+
58+
private void SetIsKinematic(bool isKinematic)
59+
{
60+
#if UNITY_2022_3_OR_NEWER
61+
m_Rigidbody.bodyType = isKinematic ? RigidbodyType2D.Kinematic : RigidbodyType2D.Dynamic;
62+
#else
63+
m_Rigidbody.isKinematic = isKinematic;
64+
#endif
5665
}
5766

5867
/// <summary>
@@ -89,7 +98,7 @@ private void UpdateOwnershipAuthority()
8998
}
9099

91100
// If you have authority then you are not kinematic
92-
m_Rigidbody.isKinematic = !m_IsAuthority;
101+
SetIsKinematic(!m_IsAuthority);
93102

94103
// Set interpolation of the Rigidbody2D based on authority
95104
// With authority: let local transform handle interpolation

testproject/Assets/Tests/Runtime/Physics/NetworkRigidbodyTests.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,21 @@ private void TestRigidBody2D()
9797
Assert.True(serverClientPlayerNetworkRigidbody2d.WasKinematicBeforeSpawn);
9898
Assert.True(clientServerPlayerNetworkRigidbody2d.WasKinematicBeforeSpawn);
9999

100-
// Validate kinematic settings after spawn
101-
var serverLocalPlayerRigidbody2d = m_ServerNetworkManager.LocalClient.PlayerObject.GetComponent<Rigidbody2D>();
102-
var clientLocalPlayerRigidbody2d = m_ClientNetworkManagers[0].LocalClient.PlayerObject.GetComponent<Rigidbody2D>();
103-
var serverClientPlayerRigidbody2d = m_PlayerNetworkObjects[m_ServerNetworkManager.LocalClientId][m_ClientNetworkManagers[0].LocalClientId].GetComponent<Rigidbody2D>();
104-
var clientServerPlayerRigidbody2d = m_PlayerNetworkObjects[m_ClientNetworkManagers[0].LocalClientId][m_ServerNetworkManager.LocalClientId].GetComponent<Rigidbody2D>();
105-
106100
var isOwnerAuthority = m_AuthorityMode == NetworkTransformRigidBodyTestComponent.AuthorityModes.Owner;
107101
if (isOwnerAuthority)
108102
{
109103
// can commit player has authority and should have a kinematic mode of false (or true in case body was already kinematic).
110-
Assert.True(!serverLocalPlayerRigidbody2d.isKinematic);
111-
Assert.True(!clientLocalPlayerRigidbody2d.isKinematic);
112-
Assert.True(serverClientPlayerRigidbody2d.isKinematic);
113-
Assert.True(clientServerPlayerRigidbody2d.isKinematic);
104+
Assert.True(!serverLocalPlayerNetworkRigidbody2d.IsKinematic());
105+
Assert.True(!clientLocalPlayerNetworkRigidbody2d.IsKinematic());
106+
Assert.True(serverClientPlayerNetworkRigidbody2d.IsKinematic());
107+
Assert.True(clientServerPlayerNetworkRigidbody2d.IsKinematic());
114108
}
115109
else
116110
{
117-
Assert.True(!serverLocalPlayerRigidbody2d.isKinematic);
118-
Assert.True(clientLocalPlayerRigidbody2d.isKinematic);
119-
Assert.True(!serverClientPlayerRigidbody2d.isKinematic);
120-
Assert.True(clientServerPlayerRigidbody2d.isKinematic);
111+
Assert.True(!serverLocalPlayerNetworkRigidbody2d.IsKinematic());
112+
Assert.True(clientLocalPlayerNetworkRigidbody2d.IsKinematic());
113+
Assert.True(!serverClientPlayerNetworkRigidbody2d.IsKinematic());
114+
Assert.True(clientServerPlayerNetworkRigidbody2d.IsKinematic());
121115
}
122116
}
123117
#endif

testproject/Assets/Tests/Runtime/Physics/NetworkTransformRigidBodyTestComponent.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,19 @@ public class NetworkRigidbody2DTestComponent : NetworkRigidbody2D
2626
{
2727
public bool WasKinematicBeforeSpawn;
2828

29+
30+
internal bool IsKinematic()
31+
{
32+
#if UNITY_2022_3_OR_NEWER
33+
return GetComponent<Rigidbody2D>().bodyType == RigidbodyType2D.Kinematic;
34+
#else
35+
return GetComponent<Rigidbody2D>().isKinematic;
36+
#endif
37+
}
38+
2939
protected override void OnNetworkPreSpawn(ref NetworkManager networkManager)
3040
{
31-
WasKinematicBeforeSpawn = GetComponent<Rigidbody2D>().isKinematic;
41+
WasKinematicBeforeSpawn = IsKinematic();
3242
base.OnNetworkPreSpawn(ref networkManager);
3343
}
3444
}

0 commit comments

Comments
 (0)