- Home /
Client objects not traveling same distance as on server before being destroyed,Network client's game objects being destroyed before traveling expected distance.
I have a 2019.1.0f2 2D project using the High Level Networking API.
The physics is fully server controlled.
There are no interacting player authoritative game objects.
The characters in the scene shoot bullets at each other.
The bullets are prefabs with network identities.
The bullets are spawned by the server using NetworkServer.Spawn(prefab);.
The bullets have a Network Transform with Transform Sync Mode: Sync Regidbody 2D.
The bullets have logic like:
void OnTriggerEnter2D(Collider2D col) {
if (isServer) {
NetworkServer.Destroy(gameObject);
}
}
All works as expected on the server.
But on the client I'm finding that the bullet game object is destroyed before the bullet reaches its target. Put another way, if I draw a line from the start point of the bullet to the end point of the bullet the line on the server simulation is longer.
The bullets are moving pretty fast, so my assumption is that the client is getting the NetworkServer.Destroy command before the client's physics simulation is caught up to where the server simulation was when the bullet was destroyed.
As a sort of test, I replaced NetworkServer.Destroy(gameObject); with gameObject.setActive(false);. This of course did not destroy the bullets on the client, but it caused the bullet to stop in the location that it was destroyed on the server. This is the behavior I want. Only I'd like the objects to actually be destroyed. I can think of some ways to do this using gameObject.setActive(false);, but they seem very hacky.
My question is: Is there a best practice way to get the bullets on the client to not be destroyed until they have traveled the same path as they traveled on the server?
Or maybe something above rings false and I'm doing something silly?
Thank you very much for any help!
Your answer
![](https://koobas.hobune.stream/wayback/20220612202320im_/https://answers.unity.com/themes/thub/images/avi.jpg)