Photon Problem. Spawn Players.

Hello. I’ve got a problem with spawning players in Photon.

I’m using exitgames tutorial for PUN. Everything seems fine with that example, but i’m trying to do the same steps with my own project. I’m using simple cubes as player object.

I’m creating player using this:

void OnJoinedRoom()
	{
		GameObject player = PhotonNetwork.Instantiate("Cube", new Vector3(0f, 0.5f, 0f), Quaternion.identity, 0);
		CubeController controller = player.GetComponent<CubeController>();
		controller.enabled = true;
	}

I added PhotonView component to my playerprefab and attach a NetworkManager script with SerializeView to Observe field:

public void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info)
	{
		if (stream.isWriting)
		{
			stream.SendNext(transform.position);
			stream.SendNext(transform.rotation);
		}
		else
		{
			this.correctPlayerPos = (Vector3)stream.ReceiveNext();
			this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
		}
	}

When i create a room, everything is ok, the first cube is created and moving.
But when i connect to the existing room, both cubes appears in the same start position, and in the next frame the first cube moving to its actual pos. Why is that happening?

You two instance object created at same position because of this line

    PhotonNetwork.Instantiate("Cube", new Vector3(0f, 0.5f, 0f), Quaternion.identity, 0);

You have to apply some form of randomness in positioning cube object. So each cube creates its unique position so no conflict occur at start up.