How do I destroy mass amounts of objects

I have a huge city in my game. I also have a monster that destroys buildings. How do I destroy the buildings he comes across? If I use the normal destroy, it doesn’t happen for all players. I can’t use PhotonNetwork.Destroy() because that would require each building having a photon view. I tried adding a photon view just before I call PhotonNetwork.Destroy() but it didn’t work.

Current code (other players see explosion but the building stays)

    void OnControllerColliderHit(ControllerColliderHit hit)
    {
        if ( hit.gameObject.CompareTag("Building") )
        {
            PhotonNetwork.Instantiate("Explosion", hit.transform.position, Quaternion.identity);
            Destroy(hit.gameObject);
        }
    }

Give each building a unique ID. When a building is destroyed, have it tell the BuildingManager to send an RPC to all the clients telling them to destroy the building with that ID. The BuildingManager exists so that each Building doesn’t require a view, only the manager does. It has a dictionary where buildings register by their unique ID so each client can look up their local instance of the building.

1 Like