Change transform.parent in RPC

Options
I'm trying to switch weapons for a client, and i want everybody to see it so i tried this

[code2=csharp]GameObject GO;
GO = PhotonNetwork.Instantiate("Pistol", Vector3.zero, Quaternion.identity, 0);
this.photonView.RPC("ParentWeapon",PhotonTargets.AllBuffered,GO);

[RPC]
void ParentWeapon (GameObject weapon)
{
if(weapon !=null)
{
weapon.transform.parent = rightHand;
weapon.transform.localPosition = Vector3.zero;
}
}[/code2]

But i get this error and it doesn't parent the object. What am i doing wrong?

[code2=csharp]SystemException: cannot serialize(): UnityEngine.GameObject
ExitGames.Client.Photon.Protocol.Serialize (System.IO.MemoryStream dout, System.Object serObject, Boolean setType)
ExitGames.Client.Photon.Protocol.SerializeObjectArray (System.IO.MemoryStream dout, System.Object[] objects, Boolean[/code2]

Comments

  • 2Kin
    Options
    You can't relay GameObject via RPC.
    Instead, you just have to command the instantiation via RPC :

    [code2=csharp]// no bufferisation as switching may occur often
    this.photonView.RPC("ParentWeapon",PhotonTargets.All,"Pistol");

    // don't forget to test if there is not already an object in your hand !
    [RPC]
    void ParentWeapon (String resourcesName)
    {
    GameObject GO;
    GO = Instantiate(Resources.Load(resourcesName), Vector3.zero, Quaternion.identity);
    GO.transform.parent = rightHand;
    GO.transform.localPosition = Vector3.zero;
    }[/code2]
  • 2Kin wrote:
    You can't relay GameObject via RPC.
    Instead, you just have to command the instantiation via RPC :

    [code2=csharp]// no bufferisation as switching may occur often
    this.photonView.RPC("ParentWeapon",PhotonTargets.All,"Pistol");

    // don't forget to test if there is not already an object in your hand !
    [RPC]
    void ParentWeapon (String resourcesName)
    {
    GameObject GO;
    GO = Instantiate(Resources.Load(resourcesName), Vector3.zero, Quaternion.identity);
    GO.transform.parent = rightHand;
    GO.transform.localPosition = Vector3.zero;
    }[/code2]

    Thank you! it seems to be working.