Search Unity

Incorrect object transform after changing ownership

Discussion in 'Netcode for GameObjects' started by jsr2k1, Mar 2, 2022.

  1. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    Hello,

    When I change the ownership of one object from the host to a client, the position of this object is changed to the last position of the client, so it's incorrect. But, when I change the ownership from the client to the host then everything is fine.

    I just change the ownership like this:

    Code (CSharp):
    1. [ServerRpc]
    2.     public void RequestOwnershipServerRpc(ulong newOwnerClientId, NetworkObjectReference networkObjectReference)
    3.     {
    4.         if(networkObjectReference.TryGet(out NetworkObject networkObject)) {
    5.             networkObject.ChangeOwnership(newOwnerClientId);
    6.         }
    7.     }
    Any suggestions?

    Thanks
     
  2. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    I can confirm this issue. In my case I was able to solve it by calling a ClientRpc that sets the position of the client object when changing the ownership, but this resetting of the transform seems like unintended behaviour.
     
  3. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    487
    You may want to report it as a bug.
     
  4. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    Thanks @CosmoM , I just fixed the problem:

    Code (CSharp):
    1. [ServerRpc]
    2. public void RequestOwnershipServerRpc(ulong newOwnerClientId, NetworkObjectReference networkObjectReference)
    3. {
    4.     if(networkObjectReference.TryGet(out NetworkObject networkObject)) {
    5.         networkObject.ChangeOwnership(newOwnerClientId);
    6.         FixPositionClientRpc(SceneManager.instance.cajon.transform.position);
    7.     }
    8. }
    9.  
    10. [ClientRpc]
    11. public void FixPositionClientRpc(Vector3 position)
    12. {
    13.     SceneManager.instance.cajon.transform.position = position;
    14. }