PUNRpc can't change Image sprite

Options
Hello !

I have a prefab with the following hierarchy :

Player
Hand1
image1
image2
image3
Hand2
image4
image5
image6

i put the photonView component only on the player gameobject (not in all the children).

When i use PUNRpc other player can't see the the sprite changes in the images.

This is the script :

void Start() {
photonView.RPC("changeImage", PhotonTargets.All);
}

[PunRPC]
public void changeImage() {
for(int i = 0; i().sprite = sprite1;
}
}
}


Please help!
Thank you!

Comments

  • Hi @liorium,

    calling a RPC in Start function works in general but should be surrounded by a photonView.isMine condition as you would do in any other case, too, otherwise each client will send this RPC when the object gets instantiated, which I guess would be the wrong behaviour. Now when sending this RPC it isn't buffered on the server, which means that late joining clients won't receive this call at all and furthermore won't change anything that is done in this RPC. Buffering each RPC also isn't a good idea, so you want to think about another solution in case you have late joining clients.

    Next to the PunRPC function itself: I guess you have shorten this for this topic and made sure that it works, because I don't get what the (broken) for loop does - however I can imagine what you want to achieve. So please make sure that the logic works properly, that all used references are set up correctly and that the RPC is actually executed on remote clients that already have joined the same room.
  • liorium
    Options
    Hi @Christian_Simon

    Thanks for your reply !
    it works now. :)