Hi !
I’m making a multi-player game at the moment, and I’m having trouble to make the setup I want:
When the player connects, the server correctly creates a “Player” object. Then, if the player wants to go into the world, he can click on a “Spawn” button so that the server creates a “Train” object (The game is about driving a train). The keypoint is that there’s a second “player-object”, the “Train” object, which is owned by the client, but the server should still have the authority on it, which is exactly how the “Player” object behaves.
The thing is that I want to be able to call [Command] methods of the “Train” object.
The first time I tried to do that, the engine threw a “Trying to send a command for non local player” message. So I changed the way I spawned the “Train” object:
[Command]
public void CmdSpawn() {
GameObject trainObject = Instantiate(trainPrefab, new Vector3(16, 0, 16), Quaternion.identity) as GameObject;
// Initialization of the object
NetworkServer.SpawnWithClientAuthority(trainObject, this.gameObject);
}
The problem is that the Unity documentation says that:
But I still want the server to be authoritative, and that the server sends “Network Transform” to the client and not the opposite (which would happen if I check the LocalPlayerAuthority property of the “Network Identity” component).
Isn’t it possible for the client to “own” an object (and being able to call [Command] methods on this object) but without having the authority of this object (So that the Position of the object is sent from the server to the client, and not vice-versa) ?
I feel like I don’t understand something, if they made it that way, they must be a reason, but I don’t get why.
Thanks in advance !
Edit: My other solution is to make proxy [Command] methods in the “Player” object that just directly call the method in the “Train” object, but I would have to do a lot of boilerplate code.