I am making a multiplayer game and I want to have player to interact with a non-player object (whose transform can be changed by any player). When I interact them with the player who joined first (or the guy who is hosting) its working but if I try to interact it with the another player (the one who joined second) the objects goes back to the location that the first player left him at.
So what I tried is to shift the authority of non-player object but I am having the following errors. Anyone is having the same issue or knows any other way to do the above task? I am using the following code to change the authority:
[Command]
void Cmd_AssignLocalAuthority(GameObject obj)
{
print("shifting authority successfully");
NetworkInstanceId nIns = obj.GetComponent<NetworkIdentity>().netId;
GameObject client = NetworkServer.FindLocalObject(nIns);
NetworkIdentity ni = client.GetComponent<NetworkIdentity>();
ni.AssignClientAuthority(connectionToClient);
}
[Command]
void Cmd_RemoveLocalAuthority(GameObject obj)
{
print("reverting authority successfully");
NetworkInstanceId nIns = obj.GetComponent<NetworkIdentity>().netId;
GameObject client = NetworkServer.FindLocalObject(nIns);
NetworkIdentity ni = client.GetComponent<NetworkIdentity>();
ni.RemoveClientAuthority(ni.clientAuthorityOwner);
}
And the error I am getting is this