Network Player position resets after giving ownership back to client
Describe the bug: I change ownership of a player between server and client and after I return the ownership from the server to the client, it resets the player's position (on client side) to the values it had the last time the client had the ownership (before giving the ownership to the server). I'm on NGO 1.0.0, using the ClientNetworkTransform script from the Package Manager - NGO Example.
Expected behavior: The network player remains at the position the server moved it to.
Desktop Unity Editor: Unity 2021.1.26 "com.unity.netcode.gameobjects": "1.0.0-pre.3", "com.unity.netcode.adapter.utp": "1.0.0-pre.2", "com.unity.services.relay": "1.0.1-pre.3"
Video You can see the behaviour in this Twitch video at 2:33:00 https://www.twitch.tv/videos/1210205925
ClientNetworkTransform (With little changes and comments removed)
` using System; using Unity.Netcode.Components; using UnityEngine;
namespace Unity.Netcode.Samples { [DisallowMultipleComponent] public class ClientNetworkTransform : NetworkTransform {
public override void OnNetworkSpawn() {
base.OnNetworkSpawn();
CanCommitToTransform = IsOwner;
}
protected override void Update() {
base.Update();
CanCommitToTransform = IsOwner;
if (NetworkManager.Singleton != null && (NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsListening)) {
if (CanCommitToTransform) {
try {
TryCommitTransformToServer(transform, NetworkManager.LocalTime.Time);
} catch (NullReferenceException exception) {
Debug.Log(exception);
}
}
}
}
}
} `
Bump - I need to change the ownership of an object between the server and the client. For the client only when changing the owner, the network transform is reset to the same value it was when the client initially joined.
E.g. Server starts, network transform is moved to 3,3,3 Client joins Server moves network transform to 5,5,5 Client is assigned ownership (few ticks delay ~ 5-10) Network work transform resets to 3,3,3 on client only (server shows the network transform at 5,5,5 still)
Potentially linked to: https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/issues/694
This has been fixed with Netcode for GameObjects 1.0.2 and the Utilities package 1.3.1 release