Can Adding new RPCs cause new game version delay or lag?

Options

Hi, I would like to ask for help or any suggestions.

My Game has 3 scenes

  1. Main Menu (no connection to Photon)
  2. Lobby (when complete connected to Photon master and joined Lobby)
  3. Gameplay (when all clients in the room press "Ready", then the host presses "Start Game")

My Game has an AI/enemy which belongs to the host only and the host will be the one who sends any actions of this enemy to all clients. I use PunRPC functions mostly (trigger animation and active child object in enemy)

Players have Stat Hiding value, will sync value with IPunObserve

On this day, when I added new PunRPC functions normally and tested the game with my team. The lag or delay happens, I will tell my situation here:

My Team were a host

I was a client

In Lobby we can select a character and change our name, the host was delayed updating the character and name for the client to see while the client normal updated for the host to see. and this delay continued to Gameplay Scene.

My Team tested their internet, and it works normally.

Then I decided to comment out new PunRPC functions, the delay it's not happening, or we back to play an old version of the game it works normally without the delay

Here It's my questions:

  1. Is there something I missing?
  2. My quite sure that I can not avoid not using PunRPcs functions but why does adding new ones cause delays in my game. RaiseEvent to not my first choice too.
  3. I do "Refresh RPCs", but never Clear RPCs before I'm not sure it's help

I using Unity version 2020.3.33f1 with PhotonPun version 2.40, lib 4.1.6.11

Thank you.

Comments

  • Tobias
    Options

    Normally, RPCs don't add delays. You may be sending them very often by accident or you run some code in them that delays the execution and everything else.

    Sending a lot of data in a single message or many messages, may cause lag (especially, as RPCs are reliable and sequenced).

    Please figure out if either is the case.

  • AlittleBB
    AlittleBB
    edited June 2022
    Options

    Tobias, thank you for your reply

    "Sending a lot of data in a single message or many messages may cause lag (especially, as RPCs are reliable and sequenced)."

    It makes me think about something in my code. and forget to mention

    In Lobby to update the player character and name, I use photonView.RPC(), RpcTarget.Others on VoidUpdate()

    this one relates, so I will look at it, but I have always used this method. before the delay I found.

    So if I change to sync value with IPunObserve, it could be better than photonView.RPC()?

    But it's still a good point, I should look at it.

    Thank you.

  • AlittleBB
    AlittleBB
    edited June 2022
    Options

    Update in my case

    I've changed the way to send value

    from

    PhotonView.RPC();

    to

    IPunObserve

    by adding this interface to my PlayerInfo class and write

    if (stream.IsWriting)
    {
        stream.SendNext(PlayerName);
        stream.SendNext(PlayerCharacter);
    }
    else
    {
        PlayerName = (string)stream.ReceiveNext();
        PlayerCharacter = (int)stream.ReceiveNext();
    }
    

    the delay was gone, and the game now works normally.