Search Unity

Help Wanted (PhotonPUN) What's a good way to handle RPCs on potentially-destroyed objects?

Discussion in 'Multiplayer' started by AidanofVT, Mar 31, 2021.

  1. AidanofVT

    AidanofVT

    Joined:
    Nov 10, 2019
    Posts:
    104
    Hi, I have a sceniario where there are a lot of RPC calls being made on a game object, any one of which could potentially result in that object calling PhotonNetwork.Destroy on itself. Predictably, this occcasionally results in RPC-method-not-found-on-object errors, because a bunch of the RPCs come in, and before the last RPC is completed, the target has been destroyed and a new object of a different kind has already taken the photonview ID number.

    This seems like a fairly mundane scenario to me, so I'm guessing there are some reliable ways to handle it. Any tips?
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,712
    RPCs target a specific PhotonView. This basically makes up the networked object.
    When this is destroyed ... you should not be able to call RPCs on it anymore. If this happens anyways, this obviously leads to undefined behavior or at least .. logs.
    You can decide this is what you want, then .. get rid of the logs. If it's working for you, no problem.

    You could also use RaiseEvent instead and send the events to manage your objects in the specific way your game needs it. PUN uses RaiseEvent for RPCs, too.

    https://doc.photonengine.com/en-us/pun/v2/gameplay/rpcsandraiseevent
     
  3. AidanofVT

    AidanofVT

    Joined:
    Nov 10, 2019
    Posts:
    104
    Thanks, yeah, I've been considering converting some RPCs to RaiseEvent.
     
unityunity