In my multiplayer scene players can spawn cubes and when one of the players clicks on any of the cubes I assign client authority to them, parent the cube to the players head and calls a command on the cube to freeze its rotation in the RigidBody Constraints. This runs fine on the host however the issue I came across was when a client attempts the same action I get an error saying that It doesn’t have authority to run the command. I noticed that I could run the command on the cube in later Update() calls. So I then implemented a timer that waits for four Update() calls and then calls the command on the cube to freeze rotation. This workaround doesn’t satisfy me though.
TL;DR It seems that client authority is assigned immediately on calling it, however I cannot call commands on the newly reassigned object until 4 Updates() have passed.
So I guess my question is: Why don’t I have authority to call commands on a newly reassigned object and what is actually going on with AssignClientAuthority?
Before the client would call a command to AssignClientAuthority then after that command would try to access the newly assigned object and call commands on a script on that. It seems that AssignClientAuthority was setting the authority on the server and it took a few updates for the client to receive the update on the authority property and so couldn’t call commands until it had been updated. Now I am calling these commands on the object from within the command on the player since the server knows straight away who has authority and this seems to work.
I do still seem to get inconsistent behaviour from NetworkIdentity.connectionToClient which I am using to AssignClientAuthority to the player. Sometimes it report a connection and other times not and this is affected from changes to seemingly unrelated code. Is there a known issue with NetworkIdentity.connectionToClient?