RPC Only Calling on Master Client

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

RPC Only Calling on Master Client

SonoDan
2022-08-30 15:31:04

I am trying to call all instantiated players to a set position in the world . I have a PhotonView as well as the" StudentClientMoveToMasterPos " Script on the root of the Player.

I have tried calling event from UI button press on the Player Prefab.

I have also tried calling from Button Press on Scene GameObject .

Both only seem to call the method on the MasterClient / or on an object with a direct reference. I can loop through a list of "Player" tagged objects and filter out the transform.root to get the reference for the player. But I thought if the GameObject contained the PView and script with the RPC Method, then it should be received and called and run on that object .

Have been going round in circles with this , so cant see what I'm doing basically wrong ....

pun 2.39 unity 2021.2.8f1 VR Project: XR interaction 2.0.1

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Photon.Pun;

// just trying to get basic function of all players with this script to goto position

public class StudentClientMoveToMasterPos : MonoBehaviourPun

{

public PhotonView pView;

void Start()

{

pView = GetComponent();

}

public void FetchAllPlayers()

{

pView.RPC("StudentsToMasterPos_PUN", RpcTarget.AllBuffered);

}

[PunRPC]

public void StudentsToMasterPos_PUN()

{

transform.position = new Vector3(0, 0.6f, 1f);

}

}

Comments

Tobias
2022-08-31 14:27:26

If it calls your RPC method locally, it should do the same on all other clients in the same room.

Anything in the logs locally or on the other players?

Two tips: MonoBehaviourPun.photonView can be used and I would not use RpcTarget.AllBuffered unless you need this stored and done by joining players later on.

SonoDan
2022-09-07 13:14:43

Thanks very much for the reply.

Its difficult to test Logs as its VR Multiplayer and I can only have 1 x Player in Editor ( via Oculus Link ).

But this Player shows no errors at all.

I can only get RPC methods to call by Foreach Looping through instantiated players to get their reference and calling them to set position . It works, so that will do for now. But I feel like it a process that might overkill.

To Summarise: I have never had a problem calling/receiving RPC on referenced objects.

I thought that RPCs were "broadcast " to all PhotonViews and picked up on all objects with "..relevantMethod() " attached. I must need to get a better understanding, so need to know this idea is not correct.

BrightSide: I now realise the danger of AllBuffered vs All etc.

ManyThanks

Tobias
2022-09-07 13:27:50

RPCs call said method on the same object (with the same PhotonView on it).

Here is more about RPCs.

Back to top