GetComponent on Network Instantiated Object

I think the title says it all. I am trying to instantiate an object over the Network with variables, but they are not sinced to the other clients. Here is my code:

[code2=csharp]GameObject WeaponDrop = PhotonNetwork.Instantiate(wp.WeaponDrop, CurPos, CurRot, 0) as GameObject;
WeaponDrop.GetComponentInChildren<DroppedWeapons>().Ammo = wp.Ammo;
if(wp.NeedsToReload == true)
{
WeaponDrop.GetComponentInChildren<DroppedWeapons>().Ammo += wp.BulletsLeft;
}
WeaponDrop.GetComponentInChildren<DroppedWeapons>().Name = wp.Name;[/code2]

Anybody know why? I also do not seem to be able to destroy the object if I am on a different client. Would be great if someone could help me! Thank you in advance.

Comments

  • Hehe. Sorry but the title doesn't say anything really.
    I guess you expect that the values you set after Instantiate will be synced to the other clients, too? You can send some data along with the Instantiate but you need to provide that in the Instantiate-call. You could send BulletsLeft along with the Instantiate but you will have to apply that value on the receiving clients with your own code.
    You can also use RPCs or OnPhotonSerializeView to synchronize what type of weapon you instantiated.

    In best case, the prefab defines everything needed to instantiate the GameObject on all client in the very same way.
  • Oh sorry I thought wrong then >.< Haha thanks for the help, I guess you did interpret it correctly after all. I think what I might do is call an RPC on the instantiated object that will sync things.

    Edit: This is how I fixed it basically. I called a function via "GetComponent" (which is not an RPC) on the object, which then calls an RPC from the photonView of the object that was instantiated. Worked perfectly 8-)