Search Unity

  1. We have added dedicated sub-forums for UNet, the experimental MLAPI and Unity Transport Package. Please use the new forums to discuss related topics.
    Dismiss Notice
  2. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

Photon PUN - MessageInfo Sender may be null, what are the alternatives?

Discussion in 'Multiplayer' started by Paulx774, Jul 15, 2021.

  1. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    62
    I need to know who sends RPC to the other players in the game. According to the document, when an RPC is called, a variable (PhotonMessageInfo) including sender info is automatically sent as well. When I checked the variable info.Sender, the description of the variable says it may be null.

    What are the situations that the variable may be null? And how can I send the sender via RPC?
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,642
    An event can be sent by the server, who is not represented as player. Event Join and other updates coming from the server will have no Sender as such.
    RPCs always have some origin. Just check if the Sender is non-null. Throw an error if any update / event should be coming from another player but it doesn't have a Sender.
     
  3. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    62
    As long as, I don't use buffered RPCs or RPCs via Server, the sender is not null? Is that correct?
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,642
    Even buffered RPCs are sent by some player, so the Sender is usually known. I write "usually" because in theory you could keep someone's RPCs buffered, even if that person leaves. In that case, the buffered RPC belongs to a player which a joining client doesn't know and then the Sender is null.

    The RPC "Via Server" option is about how the RPC gets executed on the sender itself. When sent "Via Server", the RPC makes a roundtrip and the local player executes it delayed (but at about the same time as everyone). Without that, the RPC gets executed immediately locally (which gives a slight benefit and short desync).
     
    Paulx774 likes this.
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,642
    By the way: We'd recommend to use Fusion for new-ish projects. It has a solid tick based system, provides lag compensated hit checks and is properly host / server authoritative.
    There is a preliminary doc for developers coming from PUN 2, to get you started with Fusion.

    It does have RPCs as well ;)
     
    Paulx774 likes this.
unityunity