Search code examples
unity-game-engineunity3d-unet

RemoveClientAuthority() still seems to be broken in 5.4.0 F3. Is this a BUG? ...or what do I do wrong


This is the same problem as in http://forum.unity3d.com/threads/re...ms-to-be-broken-in-5-2-1.359149/#post-2785856

My problem is the following:

1) Assign client authority to object: AssignClientAuthority

2) Move object, that works

3) Apply RemoveClientAuthority and the object snap back to original position on client side. The "TEST" call is just to see if it apply to the last object.

Is this a bug or is it me who doing something wrong?

Here is a code example from a test i do:

    foreach (string tagName in MP_Singleton.Instance.master_Object_List) {

        temp_GameObject = GameObject.FindWithTag(tagName);

        Cmd_LocalAuthority (true, temp_GameObject);

        temp_GameObject.GetComponent<Renderer>().sortingOrder = z;

        randomX = UnityEngine.Random.Range (-0.055f, 0.055f);
        randomY = UnityEngine.Random.Range (-0.055f, 0.055f);
        randomX = randomX + deckStartPosX;
        randomY = randomY + deckStartPosY;

        Rpc_Position (temp_GameObject, randomX, randomY, z, twistAngle);

        // Add to depth
        z++;

    }

    Cmd_LocalAuthority (false, temp_GameObject); //<< TEST

RPC:

[ClientRpc]
void Rpc_Position(GameObject myGO, float ranX, float ranY, int zDepth, float twist) {

    myGO.transform.position = new Vector3 (ranX, ranY, zDepth);
    myGO.transform.localEulerAngles = new Vector3(0f, 0f, twist);

}

Cmd_LocalAuthority:

[Command]
void Cmd_LocalAuthority(bool getAuthority, GameObject obj) {

    objNetId = obj.GetComponent<NetworkIdentity> ();        // get the object's network ID

    if (getAuthority) {
        objNetId.AssignClientAuthority (connectionToClient);    // assign authority to the player
    } else {
        objNetId.RemoveClientAuthority (connectionToClient);    // remove the authority from the player
    }
}

Solution

  • The great people at Unity helped me solve this problem, it was my own mistake.

    What i spend at least 2 - 3 month on trying to fix they fixed immediately.

    What i missed was that i had a check for authority in my pos-sync-script that caused the problem. It is in the "Cmd_ProvidePositionToServer".

    Here is the code:

    using UnityEngine;
    using System.Collections;
    using UnityEngine.Networking;
    
    public class Object_SyncPosition : NetworkBehaviour {
    
    private Transform myTransform;
    [SerializeField] float lerpRate = 5;
    [SyncVar] private Vector3 syncPos;
    private NetworkIdentity theNetID;
    
    private Vector3 lastPos;
    private float threshold = 0.5f;
    
    
    void Start () {
        myTransform = GetComponent<Transform> ();
        syncPos = GetComponent<Transform>().position;
    }
    
    
    void FixedUpdate () {
        TransmitPosition ();
        LerpPosition ();
    }
    
    void LerpPosition () {
        if (!hasAuthority) {
            myTransform.position = Vector3.Lerp (myTransform.position, syncPos, Time.deltaTime * lerpRate);
        }
    }
    
    [Command]
    void Cmd_ProvidePositionToServer (Vector3 pos) {
        syncPos = pos;
    }
    
    [ClientCallback]
    void TransmitPosition () {
        if (hasAuthority  && Vector3.Distance(myTransform.position, lastPos) > threshold) {
            Cmd_ProvidePositionToServer (myTransform.position);
            lastPos = myTransform.position;
        }
    }
    }