We are building a real time strategy game on Unity and trying to destroy gameobjects on the server and the clients via network. Currently a player can always destroy his own objects and the server can destroy all objects. But when a client tries to destroy objects of the server (or other clients) it only gets destroyed on this client. (As the client neither hasAuthority nor the object isLocalPlayer)
We tried different approaches:
1. Using Destroy(gameObject)
This will obviously not work as it gets only destroyed locally.
2. Using NetworkServer.Destroy(gameObject)
This fails as we don't have the authority.
3. Using a command to destroy the object
The moment we try to call a command on the server in which we destroy the object fails as well. Due to the authority check:
Trying to send command for object without authority.
4. First assigning the authority
We tried to assign the authority via
GetComponent<NetworkIdentity>().AssignClientAuthority(connectionToClient);
but get the Error Message:
AssignClientAuthority can only be call on the server for spawned objects.
Trying to do this in a Command will fail due to Point 3.
Are there other possibilities to destroy gameObjects? What is the way to go for destroying the gameObjects?
Edit: We spawned most of the objects during runtime (in a Command) via NetworkServer.SpawnWithClientAuthority
or NetworkServer.Spawn
NetworkServer.Spawn
to create the object you're trying to delete? – Ruzihm