-
Notifications
You must be signed in to change notification settings - Fork 459
Description
Description
I ran into a reproducible NullReferenceException when using NetworkRigidbody2D with a Rigidbody2D whose interpolation mode is set to Extrapolate.
This happens during multiplayer spawning on the non-owner/client side. Changing the same Rigidbody2D interpolation setting from Extrapolate to Interpolate makes the issue disappear immediately.
This makes it look like a package bug in NGO rather than a project-side null reference.
Versions
- Netcode for GameObjects:
2.11.0 - Unity Transport:
2.6.0 - Multiplayer Services:
2.0.0
Reproduction Steps
- Create a networked prefab with:
NetworkObjectNetworkTransformRigidbody2DNetworkRigidbody2D
- Set the prefab's
Rigidbody2D.interpolationtoExtrapolate. - Spawn the prefab in a multiplayer session (in my case as a player object).
- Connect a client / let the non-owner instance spawn.
Expected Result
The object should spawn normally, and NGO should handle NetworkRigidbody2D without errors.
Actual Result
A NullReferenceException is thrown during spawn/initialization.
Stack Trace
NullReferenceException: Object reference not set to an instance of an object
Unity.Netcode.Components.NetworkRigidbodyBase.UpdateOwnershipAuthority () (at ./Library/PackageCache/com.unity.netcode.gameobjects@02e4aaa4170c/Runtime/Components/NetworkRigidBodyBase.cs:993)
Unity.Netcode.Components.NetworkTransform.InternalInitialization (System.Boolean isOwnershipChange) (at ./Library/PackageCache/com.unity.netcode.gameobjects@02e4aaa4170c/Runtime/Components/NetworkTransform.cs:3743)
Unity.Netcode.Components.NetworkTransform.Initialize () (at ./Library/PackageCache/com.unity.netcode.gameobjects@02e4aaa4170c/Runtime/Components/NetworkTransform.cs:3809)
Unity.Netcode.Components.NetworkTransform.OnNetworkSpawn () (at ./Library/PackageCache/com.unity.netcode.gameobjects@02e4aaa4170c/Runtime/Components/NetworkTransform.cs:3612)
Unity.Netcode.NetworkBehaviour.NetworkSpawn () (at ./Library/PackageCache/com.unity.netcode.gameobjects@02e4aaa4170c/Runtime/Core/NetworkBehaviour.cs:814)
Workaround
Changing Rigidbody2D.interpolation from Extrapolate to Interpolate fixes the problem.
Additional Notes
While investigating this locally, I noticed code in NetworkRigidBodyBase that appears to access the 3D rigidbody field during the extrapolation path:
if (UseRigidBodyForMotion)
{
if (NetworkTransform.Interpolate && m_OriginalInterpolation == InterpolationTypes.Extrapolate)
{
if (IsKinematic())
{
if (m_InternalRigidbody.interpolation == RigidbodyInterpolation.Extrapolate)For NetworkRigidbody2D, this looks suspicious because the 2D path should not be relying on m_InternalRigidbody.