Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all articles
Browse latest Browse all 8947

RPC with PhotonTargets.Others does not reach others.

$
0
0
Hello.
I've recently decided to convert my project from Unity's Networking to Photon. Now I am in the process of reworking everything. For the most part I can see that Photon has a simpler way of getting things done (in comparison to UNET), but for the love of me I cannot get RPC related stuff to work.

In my scenario, what I was looking for is a way for one player to tell another player that he has been pushed. I've tried to send the rpc call directly to that player using

var photonOwner = obj.gameObject.GetComponent<PhotonView>().owner;
and then later
photonView.RPC("GetPushed", photonOwner, force);

but this never reaches the desired player. I tried using PhotonPlayer.Find() with the ownerId, but it never reached either.
So instead I'm working around this by using

int photonID = obj.gameObject.GetComponent<PhotonView>().ownerId;
and
photonView.RPC("GetPushed", PhotonTargets.Others, force, photonID);

and in the RPC
[PunRPC]
public void GetPushed(Vector2 force, int photonID)
{
if (photonView.isMine)
{
Debug.LogError("My ID is " + this.photonView.ownerId + " and target id is " + photonID);
if (this.photonView.ownerId == photonID)
{
Debug.LogError("IDs are equal and I am pushed with force: " + force);

pushedForce = force;
pushed = true;
}
}
}
The first Debug of this RPC is never called on any of the players. And if I use PhotonTargets.All, it is called - but only on the same player that calls it. I am probably doing a fundamental mistake in this somewhere and I would appreciate if someone could help me understand RPC of Photon. I am eager to continue my work with it.

Viewing all articles
Browse latest Browse all 8947

Trending Articles