Photon RPC call help needed

Hello everybody

I have a simple RPC function in my script that gets sent to all the players in the room. The function basically tells the other players to generate a new material, but set the color value to a value from my computer. In other words, make a material and set it to a specific color only found on my system.

void DisplayBlockConstruction(int _blockInstantiatedViewID)
    {
        if (!PV.IsMine) return;


        Material blockMaterial = new(lit);
        if (ColorUtility.TryParseHtmlString("#" + playerColorValue, out Color beanColor))
        {
            blockMaterial.color = beanColor;
        }
        blockMaterial.mainTexture = proBuilderTexture;
        PhotonView.Find(_blockInstantiatedViewID).gameObject.GetComponent<MeshRenderer>().material = blockMaterial;
        PhotonView.Find(_blockInstantiatedViewID).gameObject.GetComponent<AudioSource>().PlayOneShot(placeBlock);
        PhotonView.Find(_blockInstantiatedViewID).gameObject.GetComponent<Animator>().SetBool("isActive", true);
        blockID.Add(_blockInstantiatedViewID);
        Debug.Log(_blockInstantiatedViewID);
        
        Hashtable hash = new();
        hash.Add("blockColour", playerColorValue);
        PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
    }

As you can see from the code snippet, there is a check at the top that checks if the photonview is mine. However, now, when the second client receives the RPC, they fail the photonview check and now they can’t make the new material! How can I fix this?

Hello @DemonReborn. Thank you so much for responding to me. I appreciate it so much.

However, I had some questions. I think we misunderstood something. I want the receiving end also to apply the material. It’s not that I only want the receiving end to make the material. I want the receiving end to make the material, get the correct value found on my system, and apply it to the building block.

Thank you so much. Do you know how I can modify the RPC Call?

One solution would be to move the check for the PhotonView being “mine” to the receiving end of the RPC function, rather than at the beginning of the function. This way, the material will be generated on the receiving end and the check for the PhotonView being “mine” will only prevent the material from being applied to the PhotonView on the sender’s end.

Here is an example of what the updated RPC function could look like:

void DisplayBlockConstruction(int _blockInstantiatedViewID)
{
Material blockMaterial = new(lit);
if (ColorUtility.TryParseHtmlString("#" + playerColorValue, out Color beanColor))
{
blockMaterial.color = beanColor;
}
blockMaterial.mainTexture = proBuilderTexture;
PhotonView pv = PhotonView.Find(_blockInstantiatedViewID);
if (pv.IsMine)
{
pv.gameObject.GetComponent<MeshRenderer>().material = blockMaterial;
pv.gameObject.GetComponent<AudioSource>().PlayOneShot(placeBlock);
pv.gameObject.GetComponent<Animator>().SetBool("isActive", true);
blockID.Add(_blockInstantiatedViewID);
Debug.Log(_blockInstantiatedViewID);
}
Hashtable hash = new();
hash.Add("blockColour", playerColorValue);
PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
}