PhotonView ID duplicate found
The whole answer can be found below.
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).
PhotonView ID duplicate found
ATHellboy
2017-11-18 19:16:44
I have a gameObject in my menu scene and there is a script on it which it is for RPC methods and I need to not destroy it. Also because of duplication I try to destroy it whenever I leave the room and get back to the menu and create it again. but there is a error for PhotonView ID duplication and I don't know how can I solve it. I've tried to search but didn't find anything useful.
Comments
[Deleted User]
2017-11-21 10:09:58
Hi @ATHellboy,
maybe you should consider using events in this case. Therefore I would recommend you reading the second part (RaiseEvent chapter) of the RPCs and RaiseEvent documentation page. Using Events has the advantage that you don't need to deal with PhotonView components and have the same options.
To use this approach you can create a new GameObject and attach a script to it. This script have to mark the object as DontDestroyOnLoad(this);
in its Awake function and also has to register an event handler (see link above). You can also use this object, to actually raise events by using PhotonNetwork.RaiseEvent(...). For the necessary parameters please also take a look at the link above.
If you have further questions on this topic please feel free to ask.
Hi @Christian_Simon
I didn't understand exactly how I can use RaiseEvent instead of RPC, if it is possible give a example that show that I can replace RPC with RaiseEvent. Unfortunately, I've not found any documentation about it.
For example this is my RPC function and I want to replace it with RaiseEvent:
[PunRPC]
private void RPC_CreatePlayer()
{
currentPlayer = PhotonNetwork.Instantiate(Path.Combine("Prefab", "Player"), new Vector3(0, 800, 0), Quaternion.identity, 0);
currentPlayer.name = "LocalPlayer";
currentPlayerController = currentPlayer.GetComponent();
photonView.RPC("RPC_GetOpponent", PhotonTargets.Others);
}
Or:
[PunRPC]
private void RPC_PressStart()
{
numOfplayersPressStart++;
if (numOfplayersPressStart == PhotonNetwork.playerList.Length)
{
numOfplayersPressStart = 0;
photonView.RPC("RPC_StartAutoPlaying", PhotonTargets.AllViaServer);
}
}
Hi @Christian_Simon ,
Thanks for replying.
Unfortunately I didn't understand using RaiseEvent instead of RPCs and I've not found proper documentation for it or documentation for replacing RPC with RaiseEvent, If it is possible give me a example for it. I can provide the RPC function.
For example:
[PunRPC]
private void RPC_CreatePlayer()
{
currentPlayer = PhotonNetwork.Instantiate(Path.Combine("Prefab", "Player"), new Vector3(0, 800, 0), Quaternion.identity, 0);
currentPlayer.name = "LocalPlayer";
currentPlayerController = currentPlayer.GetComponent();
photonView.RPC("RPC_GetOpponent", PhotonTargets.Others);
}
or
[PunRPC]
private void RPC_PressStart()
{
numOfplayersPressStart++;
if (numOfplayersPressStart == PhotonNetwork.playerList.Length)
{
numOfplayersPressStart = 0;
photonView.RPC("RPC_StartAutoPlaying", PhotonTargets.AllViaServer);
}
}
[Deleted User]
2017-11-23 09:28:03
Actually there is no kind of a 'porting' guide from RPCs to Events.
I guess CreatePlayer RPC is called by the MasterClient in order to notify all clients, to Instantiate their characters, isn't it? If so the MasterClient can basically use an event, too. To do so he needs to call PhotonNetwork.RaiseEvent(123, null, true, new RaiseEventOptions() { Receivers = ReceiverGroup.All});
. '123' in this case must be replaced with your unique event code for a certain event. If you don't have used any event code before you can use any value in the range of 0 to 199. 'null' is additional event content allowing you to pass additional parameters or values, I think it's not needed here. 'true' means, that you send the event reliable to make sure it definitely arrives on all clients. When creating 'new RaiseEventOptions' make sure to set the Receivers of the event, otherwise the sender itself wouldn't receive this event.
You now have to implement an OnEvent callback as stated in the guide I already mentioned before. Make sure to register your OnEvent implementation as a listener in order to handle custom events. This is described in the guide as well. In the OnEvent callback you can basically do all the stuff you would have done with RPCs, too.
Please let me know if you have further questions.
umarMukhtar
2018-04-28 06:52:45
Hi @ATHellboy, have you been find the solution about photonview duplicate id
Back to top