Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Third Party How do I destroy mass amounts of objects

Discussion in 'Multiplayer' started by jlorenzi, Jan 1, 2024.

  1. jlorenzi


    May 2, 2021
    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)
    Code (CSharp):
    1.     void OnControllerColliderHit(ControllerColliderHit hit)
    2.     {
    3.         if ( hit.gameObject.CompareTag("Building") )
    4.         {
    5.             PhotonNetwork.Instantiate("Explosion", hit.transform.position, Quaternion.identity);
    6.             Destroy(hit.gameObject);
    7.         }
    8.     }
  2. Lo-renzo


    Apr 8, 2018
    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.
    jlorenzi likes this.