Quantcast
Channel: Recent Discussions — Photon Engine
Viewing all articles
Browse latest Browse all 15755

Manual Instantiation example in docs - why is PhotonPlayer sent in RPC?

$
0
0
Hi,

I'm looking the section titled "Manual Instantiation" at the end of this page:

https://doc.photonengine.com/en/pun/current/tutorials/instantiation

In the code (copied below), the PhotonNetwork.player is sent as a parameter to the SpawnOnNetwork RPC function, however it's not used (and not explained in docs).

Could anyone tell me why you would do that? Or what the original intention was in this code?

Thanks


void SpawnPlayerEverywhere()
{
// You must be in a Room already
// Marco Polo tutorial shows how to connect and join room
// See: http://doc.photonengine.com/en/pun/current/tutorials/tutorial-marco-polo

// Manually allocate PhotonViewID
int id1 = PhotonNetwork.AllocateViewID();

PhotonView photonView = this.GetComponent<PhotonView>();
photonView.RPC("SpawnOnNetwork", PhotonTargets.AllBuffered, transform.position, transform.rotation, id1, PhotonNetwork.player);
}

public Transform playerPrefab; //set this in the inspector

[RPC]
void SpawnOnNetwork(Vector3 pos, Quaternion rot, int id1, PhotonPlayer np) //<--- np never used!
{
Transform newPlayer = Instantiate(playerPrefab, pos, rot) as Transform;

// Set player's PhotonView
PhotonView[] nViews = newPlayer.GetComponentsInChildren<PhotonView>();
nViews[0].viewID = id1;
}

Viewing all articles
Browse latest Browse all 15755

Trending Articles