- Home /
NetworkServer.Destroy(GameObject) disables Client objects instead of destroying them
Hi All,
I'm trying to have a networked (UNET, Unity 5.3.5f1) GameObject be destroyed on the Server and all Clients. I had started with this code, assuming NetworkServer.Destroy(GameObject) would, as it says, destroy the object and all corresponding objects on all Clients.
[Command]
public void CmdAddAmmo(NetworkInstanceId ammoNetID)
{
GameObject ammo = NetworkServer.FindLocalObject(ammoNetID);
// Do stuff
NetworkServer.Destroy(ammo);
}
However, this code correctly destroys the GameObject on the Server, but deactivates the object on the Clients. Now, it's easy to get around this behavior with an RPC call, but isn't the intended behavior of NetworkServer.Destroy to destroy the object across the network, not to just disable those on the Clients?
For those interested, here's my workaround:
[Command]
public void CmdAddAmmo(NetworkInstanceId ammoNetID)
{
GameObject ammo = NetworkServer.FindLocalObject(ammoNetID);
// Do stuff
RpcAddAmmo(ammoNetID);
GameObject.Destroy(ammo);
}
[ClientRpc]
public void RpcAddAmmo(NetworkInstanceId ammoNetID)
{
GameObject ammo = ClientScene.FindLocalObject(ammoNetID);
GameObject.Destroy(ammo);
}
I second it, I have a clear case of NetworkServer.Destroy() which destroys the object on the server but not on the client. The client object is simply disabled and OnDestroy is never called. I do keep references on this object through local list, would keeping a reference prevent the object from being destroyed? using 2017.1, just upgraded today.