Thanks to visit codestin.com
Credit goes to github.com

Skip to content

NetworkTransform stops syncing after repeated respawns or ownership changes #3654

@nikajavakha

Description

@nikajavakha

Description

In Distributed Authority, NetworkTransform sometimes stops working after repeatedly respawning or changing ownership.

This issue occurs randomly, usually after 3–10 cycles of despawning, respawning, and updating ownership. When this happens, movement sync completely stops for that object.

During debugging, I discovered that on the session owner’s side, the Interpolate property of the affected NetworkTransform is being set to false, while it remains true on all other clients.

To fix this, I implemented a workaround:

  • I periodically check all NetworkTransform components on the session owner’s client.
  • If I find one where Interpolate is false, I temporarily transfer ownership of that NetworkTransform to the session owner.
  • Then, I reset Interpolate to true.
  • Finally, I restore the original ownership.

Here's the code I’m using to work around the problem. It periodically checks all NetworkTransform components and resets the Interpolate property when needed.

Important Note:
If I try to reset the Interpolate property directly on its current owner, it has no effect — it only works after temporarily transferring ownership.

using System.Collections;
using Unity.Netcode;
using Unity.Netcode.Components;
using UnityEngine;

namespace Assets.Scripts
{
    public class NetworkTransformFixer : MonoBehaviour
    {
        private Coroutine _fixerCoroutine;

        private void Start()
        {
            _fixerCoroutine = StartCoroutine(PeriodicInterpolationCheck());
        }

        private void OnDestroy()
        {
            if (_fixerCoroutine != null)
            {
                StopCoroutine(_fixerCoroutine);
                _fixerCoroutine = null;
            }
        }

        private IEnumerator PeriodicInterpolationCheck()
        {
            while (true)
            {
                yield return new WaitForSeconds(1f);
                FixNetworkTransformInterpolation();
            }
        }

        private void FixNetworkTransformInterpolation()
        {
            if (!NetworkManager.Singleton.LocalClient.IsSessionOwner)
                return;
            
            var networkTransforms = FindObjectsByType<NetworkTransform>(FindObjectsSortMode.None);
            
            // Check if any NetworkTransform has interpolation issues
            foreach (var networkTransform in networkTransforms)
            {
                var originalOwner = networkTransform.OwnerClientId;
                if (networkTransform.IsSpawned && !networkTransform.Interpolate)
                {
                    networkTransform.NetworkObject.ChangeOwnership(NetworkManager.Singleton.LocalClientId);
                    networkTransform.Interpolate = true;
                    // Restore original ownership
                    networkTransform.NetworkObject.ChangeOwnership(originalOwner);
                }
            }
        }
    }
}

Environment

  • Netcode Version: v2.5.0
  • Netcode Topology: Distributed Authority

Metadata

Metadata

Labels

stat:InvestigatingIssue is currently being investigatedstat:awaiting-responseAwaiting response from author. This label should be added manually.stat:awaiting-triageStatus - Awaiting triage from the Netcode team.type:bugBug Report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions