Playing sound remotely

Options
Hello, I'm new to PUN. I'm trying to get an audio clip to play remotely. The code I have for the RPC is:

[PunRPC] void PlaySound(string soundName) { AudioSource audioRPC = gameObject.AddComponent<AudioSource>(); audioRPC.clip = remoteAudioClip; audioRPC.spatialBlend = 1; audioRPC.minDistance = 25; audioRPC.maxDistance = 100; audioRPC.Play(); Debug.Log("play sound: " + gameObject.GetComponent<PhotonView>().viewID.ToString()); }

Where "remoteAudioClip" is an audio clip added via the Inspector.

and then to call it:

gameObject.GetComponent<PhotonView>().RPC("PlaySound", PhotonTargets.Others, "gunshot");

The RPC fails with:

Received RPC "PlaySound" for viewID 1002 but this PhotonView does not exist! Was remote PV. Owner called. By: 1 Maybe GO was destroyed but RPC not cleaned up.

What is strange is that Ive done RPCs in other places in my code without any problem. Any ideas? Also, what makes up the view ID? Is it a concatenation of the player # and the view id in the inspector?

Comments

  • xlar54
    Options
    ah disregard. it wasn't so much my code as it was the parent child setup. Hard to describe.