Spawn object and enemies npc

Hi everyone I have a problem with the object and npc spawning.
I'm trying using a PunRPC method SpawnChest() and only the Master Client could spawn this object, but when other players join in match other chests will spawn...
Every chest has a trigger collider and when a player triggers the area, a defined number of npc will spawn in the area.
So I thought that when a player trigger the area, this player send to Master Client a PunRPC to invoke the npc's spawning.
Sorry for the english, but I'm so confused....

Comments

  • Hi @Danny07,

    I'm trying using a PunRPC method SpawnChest() and only the Master Client could spawn this object,


    I actually don't get who calls RPC("SpawnChest", ...). Is it the MasterClients or any other client? Some code snippets would be helpful in this case.

    So I thought that when a player trigger the area, this player send to Master Client a PunRPC to invoke the npc's spawning.


    Yes, this is possible. When sending RPCs you can also set the receivers. This is the second parameter. If you only want to send the RPC to the MasterClient you can use PhotonTargets.MasterClient for this parameter in order to tell the MasterClient to spawn new NPCs.

    Please also check, if you need to use RPCs for Instantiation instead of calling PhotonNetwork.Instantiate(...) which is easier to use.
  • So if I use Phototargets.MasterClient just the master client can see the actions of RPC or also the other client? Or may I use PhotonTargets.All and use a check like if(PhotonNetwork.isMasterClient)?
  • If you use PhotonTarget.MasterClient, the RPC is only forwarded to the MasterClient. If you use PhotonTargets.All, every client will receive the RPC.

    The combination of PhotonTargets.All and PhotonNetwork.isMasterClient condition in the resulting RPC doesn't make sense because non-MasterClients are not interested in those RPCs and you only waste messages and traffic.
  • Ah ok, that's right thanks!!!
    So when I want attack using a specific method I must use PhotonTargets.All to send informations about the attacking phase, isn't it?
  • This one option you have, yes.

    If your attacks trigger animations, you can also take a look at the PhotonAnimatorView to synchronize the current animation. In combination with the PhotonTransformView this synchronizes the characters movement and animation state without separately calling a RPC.

    If you have damage intervals on your attacks please make sure that damage is only calculated on one client otherwise you might get unwanted desynchronization. Damage given is for example a value which should be synchronized using RPCs.