Instantiate Remote Object


I'm trying to equip an item from an existing inventory system on the remote version of my player. I've created a script to be observed by a Photon View that simply gathers the information (prefab, position, rotation, and parent), stores it in variables, and creates it on the remote version of the player. Right now, the inventory system does instantiate it correctly on the local player, so my script is only used to mirror it on the remote player, I don't need it on the local, and for this reason, I've skipped using PhotonNetwork.Instantiate on PhotonEquip below (tried that too).

To summarize, all the gathering of information is going on in my first function "SendPhotonEquip()", which is run locally. This gathers everything and stores it a variable. Then I simply call up the next function "PhotonEquip", which is supposed to be run on the remote player. Here is how I'm doing that:

photonView.RPC("PhotonEquip", RpcTarget.OthersBuffered); // Call to RPC function

I then pass it off to the actual function that creates the item:

public void PhotonEquip()
{ //This actually creates the items on the remote player.

if (!photonView.IsMine)
//Here we check to see if the Weapon variable is actually filled in (that's all handled in SendPhotonEquip). If not, then don't bother.

if (lWeaponTemp != null)
//Here we simply instantiate the object into the scene. Note that it has to have a photon view on it.
GameObject lWeaponObject = Resources.Load(lPath);
(Instantiate(lWeaponObject, lWeaponPosTemp, lWeaponRotTemp) as GameObject).transform.parent = lWeaponParent.transform;


(posted as text here, the code option was messing it up)
I've tried it with and without the if statement testing if the photonView.IsMine, and have had no luck. Am I just calling PhotonEquip the wrong way?

Any help or suggestions would be much appreciated. Thanks in advance.


  • rubblerubble
    edited January 9
    Just as an update. I've tried creating the weapon through PhotonNetwork.Instantiate. My problem seems not to be the instantiation, but calling this function itself that instantiates the item on the remote player.

    I'm calling the function up using the code mentioned above (but using AllBuffered instead of OthersBuffered).
    I tried it out in my editor, getting rid of the if statement checking if (photonView.IsMine), and it does create some extra clones locally, so something is working. However, when I try it in the build, it doesn't create the item over the network.

    By the way, I no longer seem able to test this stuff at runtime, the way I could with Photon Classic. Both players seem to connect, but are unable to see each other and play together. Is this right? It would be so much easier if I could see the instantiated remote in the editor.

    Maybe this is a silly mistake on my part, but if someone understands what I'm doing wrong here, I'd really appreciate it if you can point me in the right direction.
Sign In or Register to comment.