You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spawn and immediate re-parent of owner auth local space NetworkTransform always results in incorrect world position #3645
Spawn and immediate re-parent of owner auth local space NetworkTransform always results in incorrect world position unless you get lucky with (0,0,0) world position prefab or new parent.
Charlie avatar prefab NetworkTransform settings:
Authority Mode = Owner
Switch Transform Space When Parented = true
In Local Space = true
Host spawns Charlie avatar NetworkObject prefab that has a NetworkTransform using SpawnWithOwnership() and setting the owner to the Charlie client. The initial position of Charlie is not world 0,0,0 but some other world position e.g. (500, 0, 70)
Host immediately re-parents the Charlie avatar from initial null parent to a valid NetworkObject parent, and that new parent is not at (0,0,0), it is at some other position e.g. (100, 0, 0)
then ApplyAuthoritativeState() runs on Host and this else case executes:
if (PositionInLocalSpace)
{
// This handles the edge case of transitioning from local to world space where applying a local
// space value to a non-parented transform will be applied in world space. Since parenting is not
// tick synchronized, there can be one or two ticks between a state update with the InLocalSpace
// state update which can cause the body to seemingly "teleport" when it is just applying a local
// space value relative to world space 0,0,0.
if (SwitchTransformSpaceWhenParented && m_IsFirstNetworkTransform && Interpolate && m_PreviousNetworkObjectParent != null
&& transform.parent == null)
{
m_InternalCurrentPosition = m_PreviousNetworkObjectParent.transform.TransformPoint(m_InternalCurrentPosition);
transform.position = m_InternalCurrentPosition;
}
else // this executes!
{
transform.localPosition = m_InternalCurrentPosition;
}
}
But m_InternalCurrentPosition was still (500, 0, 70) and so now Charlie's world position is (600, 0, 70) which is incorrect.
This value will stay incorrect until the Charlie client sends new authoritative position data, and with enough lag and/or packet loss this incorrect position will be perceived by the Host, potentially for awhile.
It seems that on the host neither InternalOnNetworkObjectParentChanged() nor AdjustForChangeInTransformSpace() makes any changes to m_InternalCurrentPosition, and I wonder if they should be?
Or does there need to be an additional else if case in ApplyAuthoritativeState() for this?
There's something going on with this one where if authoritative position data comes from Charlie (but it isn't a teleport) around the time all this initial configuration and re-parenting is happening, Harry will overwrite it and preserve the incorrect m_InternalCurrentPosition... and so Harry will see the wrong position until Charlie starts moving around a bunch and eventually m_InternalCurrentPosition for Harry will reflect accurate position data.
ParrelSync with simulated 750ms lag so you can more easily see the problem.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Netcode;
using Unity.Netcode.Components;
public class Bug3645 : NetworkBehaviour
{
public Transform position1; // Not at (0,0,0)
public Transform parent1; // Not at (0,0,0)
public GameObject prefab;
void SpawnTestClientOwner()
{
var temp = GameObject.Instantiate(prefab, position1.position, Quaternion.identity) as GameObject;
NetworkObject networkObj = temp.GetComponent<NetworkObject>();
networkObj.SpawnWithOwnership( 1 ); // lazy hardcoded this, should be other non-host client tho ;)
networkObj.TrySetParent( parent1 );
}
}
Because of a bug with the owner authoritative NetworkTransform, on the host (who does not own this spawned object) you will see the object interpolate across the screen into its authoritative position from an incorrect position. ("Incorrect" being world 0,0,0 I think?)
The repro rate seems 100% for me.
Interestingly, if you use this method but with the host as the owner of the spawned object, there is still occasionally a noticeable interpolation that happens that should not be happening, but the repro rate is very low... maybe 10-20% for me.
Activity
zachstronaut commentedon Sep 3, 2025
There's something going on with this one where if authoritative position data comes from Charlie (but it isn't a teleport) around the time all this initial configuration and re-parenting is happening, Harry will overwrite it and preserve the incorrect m_InternalCurrentPosition... and so Harry will see the wrong position until Charlie starts moving around a bunch and eventually m_InternalCurrentPosition for Harry will reflect accurate position data.
zachstronaut commentedon Sep 5, 2025
Repro is very straightforward!
ParrelSync with simulated 750ms lag so you can more easily see the problem.
Because of a bug with the owner authoritative NetworkTransform, on the host (who does not own this spawned object) you will see the object interpolate across the screen into its authoritative position from an incorrect position. ("Incorrect" being world 0,0,0 I think?)
The repro rate seems 100% for me.
Interestingly, if you use this method but with the host as the owner of the spawned object, there is still occasionally a noticeable interpolation that happens that should not be happening, but the repro rate is very low... maybe 10-20% for me.
NoelStephensUnity commentedon Sep 11, 2025
Closing this issue as a duplicate of #3646 since the underlying issue was all related to the same thing.