Problem Calling an RPC
Options
I'm creating a multiplayer app in Unity using PUN2. Can anyone explain why I'm getting the following message in the Console?: PhotonView with ID 1 has no (non-static) method "StartMusicWithDelay" marked with the [PunRPC](C#) or @PunRPC(JS) property! Args: Double, Double
The following code is on a game object with a PhotonView component in the scene:
The following code is on a game object with a PhotonView component in the scene:
public override void OnPlayerEnteredRoom(Player newPlayer) { gameObject.GetComponent<PhotonView>().RPC("StartMusicWithDelay", RpcTarget.AllBuffered, startTimeFirst, hostDSP); }The following code is on the player prefab, which has a PhotonView component:
[PunRPC] void StartMusicWithDelay(double _startTimeFirst, double _hostDSP) { double hostMachineTime = _hostDSP + 1; double localStartTime = AudioSettings.dspTime + 1; double timeSinceStart = (_hostDSP - _startTimeFirst) % clipLength; int samplePosition = (int)(sampleRate * timeSinceStart); audioSource.timeSamples = samplePosition; audioSource.PlayScheduled(localStartTime); Debug.Log("StartMusicWithDelay was called. _hostDSP = "+ _hostDSP+". _startTimeFirst = "+_startTimeFirst); }
0
Best Answer
-
Hi @OjosLindos;
From the ViewId 1, we can guess that the PhotonView that you try to use for the RPC "StartMusicWithDelay" is attached to a scene object and not a player object.
Scene views' IDs are between 1 and 1000 by default.
Actor number 1's views' IDs are between 1001 and 2000.
...
This codegameObject.GetComponent<PhotonView>()
returns a PhotonView attached to a scene object. The script that hasOnPlayerEnteredRoom
callbacks you quoted is attached to the same GameObject as that PhotonView.
Try getting the correct PhotonView for the player prefab.5
Answers
-
Hi @OjosLindos;
From the ViewId 1, we can guess that the PhotonView that you try to use for the RPC "StartMusicWithDelay" is attached to a scene object and not a player object.
Scene views' IDs are between 1 and 1000 by default.
Actor number 1's views' IDs are between 1001 and 2000.
...
This codegameObject.GetComponent<PhotonView>()
returns a PhotonView attached to a scene object. The script that hasOnPlayerEnteredRoom
callbacks you quoted is attached to the same GameObject as that PhotonView.
Try getting the correct PhotonView for the player prefab.5 -
Thanks for getting back to me, @JohnTube. I moved the first code shown above (previously in a scene object script) to the same script the second code is on (player prefab). The "StartMusicWithDelay" RPC is now called.0