- Home /
Unity/Mirror Network Delay After Transferring Client Authority
This is a complicated issue so I attached a gif to show what's going on
Order of events:
Player B (on the right) is controlling the human and has client authority
Player A (on the left) hits the human with a bookshelf
Player B is removed from the human, turns back into a pink ball, and has client authority of the human removed
Player A is assigned client authority for the human
As player A moves away, locally the human model moves in sync with player A (ignore that the pink balls are not rendering while controlling the human, this is a feature)
From Player B's view, the human model slowly approaches the pink ball (Player B) while the Client Buffer and Client Catchup max out.
Finally, the human traces out the path of Player A until it finally catches up and remains in sync afterwards.
Some notes:
The first couple times the authority is switched, it does not produce the error
The effect becomes longer after each authority transfer and will eventually crash Unity
The 'hasAuthority' boolean for the Human prefab seems to be turning on and off correctly
[Network Transform for Human Prefab]
Player A calls the CmdControlPlayer function, 'other' is the human currently controlled by Player B:
[Command]
public void CmdControlPlayer(GameObject other)
{
//Unrelated code
AssignAuthority(other);
//Unrelated code
}
void AssignAuthority(GameObject other)
{
RemoveClientAuthority(other);
other.GetComponent<NetworkIdentity>().AssignClientAuthority(connectionToClient);
}
void RemoveClientAuthority(GameObject other)
{
if(other.GetComponent<NetworkTransform>().connectionToClient != null)
{
other.GetComponent<NetworkIdentity>().RemoveClientAuthority();
}
}
The input is being translated to movement as follows:
private Vector3 bodyMovement;
public GameObject possessedObject;
[SerializeField] private Rigidbody controllableBody;
//Called in Update function
void PlayerInput()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
input_X = Input.GetAxisRaw("Horizontal");
input_Z = Input.GetAxisRaw("Vertical");
// If the player is controlling the human
if(isHuman)
{
bodyMovement = (controlledObject.transform.right * input_X) + (controlledObject.transform.forward * input_Z);
controlledObject.transform.Rotate(Vector3.up * mouseX);
}
else
{
//Control pink ball
}
}
void FixedUpdate()
{
if(hasAuthority)
{
if(controlledObject != null)
{
transform.position = controlledObject.transform.position;
if(isHuman)
{
transform.rotation = controlledObject.transform.rotation;
// RigidBody Movement For Human //
controllableBody.velocity = ((bodyMovement.normalized * moveSpeed) + (transform.up * controllableBody.velocity.y));
Camera.main.transform.localRotation = Quaternion.Euler(yRotation, 0f, 0f);
}
}
}
}
My guess is that this has something to do with the buffer filling up with something but not being able to catch up for a short time. Any help would be welcome!
Using Unity 2020.3.20f1 Personal on Windows 10
Your answer
Follow this Question
Related Questions
MIRROR: Connect Android client to PC server? 2 Answers
Mirror: Can't connect to Oculus Quest 2 (Android) Host - Instant Disconnect 1 Answer
How do I update values and the transform of an object on the server's and client's side? 0 Answers
Update transform component from server every frame 1 Answer
Mirror doesn't show LAN options 0 Answers