I dont understand one of the considirations about RPC's

Options
"Do not attach more than one component of the same type and that have RPC methods on the same GameObject as a PhotonView."

What do they mean by this?

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

Comments

  • OverTheMoon
    edited June 2020
    Options
    I'm not 100% sure, but I'm pretty sure it means this:

    Photon keeps track of all the RPC functions you make (that's why you have to mark them as [PunRPC] or whatever). It keeps an internal list of each of those functions, which is how it knows how to call the right function when it gets data across the network to call a function.

    The problem is that because each function is stored with a unique address, Photon won't know which one to call if you attach two of the same script to the same object. It knows that it needs to call "Method named X" on "Script named Y" attached to "Photon View with ID: Z" but if you have multiple instances of "Script named Y" it'll get confused and break.

    Keep in mind that you can have two scripts of different types on the same object, and that should work. that's because the functions are stored differently. internally, photon will record them as something like:

    Script.MethodA
    Script2.MethodA

    Even though the "MethodA" part is the same, the full address is different. That's my guess, anyway! Hope it helps.
  • TheMagman
    Options

    Thank you for your reaction.