Syncing random player colors through PUN2

I’m using PUN2, When a player connects, I want their sprite render to be a random color, and for that color to be synced for all other players.

For some reason the following code prevents the other players from appearing on the screen however I can still see the player objects in the inspector. If I remove the RPC call, I can see the other players fine, but their colors don’t sync.

public class Player : MonoBehaviour
{
    private PhotonView myPV;
    public string nickname;
    public Color color;

    private void Awake()
    {
       

    }
    // Start is called before the first frame update
    void Start()
    {
        myPV = GetComponent<PhotonView>();
        if (myPV.IsMine)
        {
            gameObject.GetComponentInChildren<Camera>().enabled = true;
            gameObject.GetComponentInChildren<TopDownCharacter>().enabled = true;
            color = Random.ColorHSV();
            myPV.RPC("RPC_SendColor", RpcTarget.AllBuffered);
        }
    }
   

    [PunRPC]
    void RPC_SendColor()
    {
        gameObject.GetComponentInChildren<SpriteRenderer>().color = color;
    }

}

hey there,

you kind of missed how RPCs work. Your current RPC does not have any arguments. Thus it does not transport any information except for the information of it beeing called upon.
So you should change the Code something likes this:

void Start()
     {
         myPV = GetComponent<PhotonView>();
         if (myPV.IsMine)
         {
             gameObject.GetComponentInChildren<Camera>().enabled = true;
             gameObject.GetComponentInChildren<TopDownCharacter>().enabled = true;
             color = Random.ColorHSV();
             myPV.RPC("RPC_SetColor", RpcTarget.AllBuffered, color);
         }
     }
    
 
     [PunRPC]
     void RPC_SetColor(Color transferredColor)
     {
         gameObject.GetComponentInChildren<SpriteRenderer>().color = transferredColor;
     }

I did not test this and it might not work since Photon does not allow for all object types to be transferred natively. In case the type Color is not compatible with photon you have to deconstruct the color value in R,G,B and send those integers by itself or create a Serializable Color Datatype that you register as “custom datatype” with photon.