How to properly delete an object over the network?
So, I spent more than a week studying the crooked documentation, which is not clear for whom it was written, and everything that is written there does not work or works, to put it mildly, crooked.
My project is a 2D game with procedural level generation. There are players and enemies that fire bullets. These bullets are supposed to destroy themselves and the object they hit. I tried many options on how to do this, but I got a lot of errors related to deleting objects over the network.
All objects in the game scene spawn PhotonNetwork.Instantiate and have a PhotonView component.
At the moment, in order for everything to work, I delete the object like this:
private void OnTriggerEnter2D(Collider2D coll)
if (coll.CompareTag("Player") || coll.CompareTag("Enemy") || coll.CompareTag("GameWall") || coll.CompareTag("swall") || coll.CompareTag("bwall"))
and it only works if one client is running. If you run two or more clients, then it does not work well. Deleting objects is not synchronized on all clients.
How to delete an object that belongs or does not belong to the client on which it is deleted?