Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Question change ownership not working

Discussion in 'Multiplayer' started by miccalisto, Apr 23, 2023.

  1. miccalisto


    Feb 20, 2018
    The ownership change appears to work on the server side but is not properly registered on the clients side.
    In this code the first print and last print shwos the same number 0, the owner.ClientId.Value is 1, so the method ChangeOnwershipServerRpc(owner.ClientId.Value) doesn't change it.
    When using print(OwnerClientId) inside the ChangeOnwershipMethod(ulong clientId) it shows the correct owner. So why the client doesnt catch the change? I read the onwershipchange is autosynchronized.

    Maybe the the information about ownership change couldn't reach from the server to client in time? In that case how do I wait for the information.
    Code (CSharp):
    1. print(OwnerClientId);
    2. print(owner.ClientId.Value);
    3. ChangeOnwershipServerRpc(owner.ClientId.Value);
    4. print(OwnerClientId);
    Code (CSharp):
    1. [ServerRpc(RequireOwnership = false)]
    2.     private void ChangeOnwershipServerRpc(ulong clientId)
    3.     {
    4.         ChangeOnwershipMethod(clientId);
    5.     }
    7.     private void ChangeOnwershipMethod(ulong clientId)
    8.     {
    9.         GetComponent<NetworkObject>().ChangeOwnership(clientId);
    10.     }