Skip to content

NetworkTransform misses sync when GameObject is re-enabled; add option for automatic reassertion #3435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Wyndar opened this issue May 2, 2025 · 4 comments
Labels
priority:low This issue has low priority and will take some time to be resolved stat:awaiting-response Awaiting response from author. This label should be added manually. stat:imported Status - Issue is tracked internally at Unity type:feature New feature, request or improvement type:feature-2.x New NGO 2.0.0 feature, request or improvement type:support Questions or other support

Comments

@Wyndar
Copy link

Wyndar commented May 2, 2025

Description
When using NetworkTransform in server-authoritative mode, if a NetworkObject is deactivated on clients (e.g. via SetActive(false) or scene streaming), any transform changes (e.g. via Teleport) made while it's inactive are not propagated to the client once it's re-enabled. This results in position mismatches, where the client sees the object at its old position while the server has already moved it.

There is no warning, and the desync is silent unless manually corrected.

Reproduction Steps
Spawn a server-authoritative NetworkObject with a NetworkTransform

Deactivate the object on all clients (via RPC or reparenting in a disabled object)

On the server, call Teleport(...) to move the object

Reactivate the object after a short delay

Observe: the client does not reflect the new position

Expected Behavior
Clients should receive the latest authoritative position of the object when it becomes active again.

Workarounds
Currently, we must:

Reapply Teleport() after reactivating the object, or

Use a coroutine to delay the teleport until the object is re-enabled, or

Use custom NetworkVariable logic or whatever boiler plate works instead of NetworkTransform

Suggested Fixes
Add a forceResyncOnEnable bool on NetworkTransform

Internally store the last known transform state, and resend it on reactivation

Or provide an OnNetworkObjectReenabled callback for developers to manually reassert state

@marcusx2
Copy link

marcusx2 commented May 3, 2025

This is the same for ClientNetworkTransform

@github-actions github-actions bot added the stat:reply-needed Awaiting reply from Unity account label May 3, 2025
@NoelStephensUnity NoelStephensUnity added the type:support Questions or other support label May 5, 2025
@NoelStephensUnity
Copy link
Collaborator

So,
This is actually a performance related thing where if you disabled the GameObject then the NetworkTransform authority instance will exit early when checking for state changes. The assumption made was if you have disabled the GameObject then you wouldn't be moving it or be concerned of synchronizing position when something is disabled.

We could provide a property that lets you bypass this check:

        private void OnNetworkTick(bool isCalledFromParent = false)
        {
            // If not active, then ignore the update
            if (!gameObject.activeInHierarchy)
            {
                return;
            }

That would allow you to control whether it would send updates or not while it is disabled.

For the time being, something along the lines of this:

public class ControlNetworkTransform : NetworkTransform
{
    private bool m_WasDisabled;

    private void OnDisable()
    {
        if (IsSpawned && CanCommitToTransform)
        {
            m_WasDisabled = true;
        }
    }

    private void OnEnable()
    {
        if (m_WasDisabled && IsSpawned && CanCommitToTransform)
        {
            m_WasDisabled = false;
            SetState(transform.position, transform.rotation, teleportDisabled: false);
        }
    }
}

Should resolve your issue (similar to what you pointed out in the work arounds).

@github-actions github-actions bot added stat:awaiting-response Awaiting response from author. This label should be added manually. and removed stat:reply-needed Awaiting reply from Unity account labels May 5, 2025
@NoelStephensUnity NoelStephensUnity added priority:low This issue has low priority and will take some time to be resolved stat:import Status - Issue is going to be saved internally type:feature New feature, request or improvement type:feature-2.x New NGO 2.0.0 feature, request or improvement labels May 5, 2025
@michalChrobot michalChrobot added stat:imported Status - Issue is tracked internally at Unity and removed stat:import Status - Issue is going to be saved internally labels May 12, 2025
@marcusx2
Copy link

marcusx2 commented May 12, 2025

We actually only want to send updates when it is enabled, not disabled. The problem is that if you disable the gameobject, when you reenable the synchronization breaks. So you can never disable the gameobject with the networktransform.

EDIT

Just re-read the original post. In my case, I just move when it's enabled, but it still breaks if I ever disable the gameobject with the networktransform.

@github-actions github-actions bot added stat:reply-needed Awaiting reply from Unity account and removed stat:awaiting-response Awaiting response from author. This label should be added manually. labels May 12, 2025
@EmandM
Copy link
Collaborator

EmandM commented May 26, 2025

We don't seem to be able to reproduce this issue. Can you provide more details on which versions of NGO and Unity you are using, whether you are using Client Server or Distributed Authority, and what scripts you are using to both move and disable/re-enable the NetworkTransform?

@github-actions github-actions bot added stat:awaiting-response Awaiting response from author. This label should be added manually. and removed stat:reply-needed Awaiting reply from Unity account labels May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:low This issue has low priority and will take some time to be resolved stat:awaiting-response Awaiting response from author. This label should be added manually. stat:imported Status - Issue is tracked internally at Unity type:feature New feature, request or improvement type:feature-2.x New NGO 2.0.0 feature, request or improvement type:support Questions or other support
Projects
None yet
Development

No branches or pull requests

5 participants