PhotonVoiceNetwork DontDestroyOnLoad Error
Options
Malcolm
✭
in Photon Voice
I am using PUN 2 and Photon Voice 2. My game has a cycle of Lobby -> Game Scene -> Lobby, assuming the master client at least remains connected.
I am using PhotonVoiceNetwork with the built-in DontDestroyOnLoad as recommended here:
https://doc.photonengine.com/en-US/voice/current/getting-started/voice-for-pun
Photon Voice works fine both in the lobby and the game scene, however when I return to the Lobby I get this error:
[PhotonVoiceNetwork.PhotonVoiceNetwork] 2021-08-23T10:30:43:An instance of PhotonVoiceNetwork is already set. Destroying extra instance.
UnityEngine.Debug:LogErrorFormat (UnityEngine.Object,string,object[])
Photon.Voice.Unity.VoiceLogger:LogError (string,object[]) (at Assets/Photon/PhotonVoice/Code/VoiceLogger.cs:67)
Photon.Voice.PUN.PhotonVoiceNetwork:set_Instance (Photon.Voice.PUN.PhotonVoiceNetwork) (at Assets/Photon/PhotonVoice/Code/PUN/PhotonVoiceNetwork.cs:151)
Photon.Voice.PUN.PhotonVoiceNetwork:Awake () (at Assets/Photon/PhotonVoice/Code/PUN/PhotonVoiceNetwork.cs:238)
It looks like this should be normal Unity singleton behaviour - the new version gets destroyed, the old one continues. So why is it generating an error? Is there something else I have to do to make this safe? Or do I have to implement my own singleton scheme to get this to work?
I am using PhotonVoiceNetwork with the built-in DontDestroyOnLoad as recommended here:
https://doc.photonengine.com/en-US/voice/current/getting-started/voice-for-pun
Photon Voice works fine both in the lobby and the game scene, however when I return to the Lobby I get this error:
[PhotonVoiceNetwork.PhotonVoiceNetwork] 2021-08-23T10:30:43:An instance of PhotonVoiceNetwork is already set. Destroying extra instance.
UnityEngine.Debug:LogErrorFormat (UnityEngine.Object,string,object[])
Photon.Voice.Unity.VoiceLogger:LogError (string,object[]) (at Assets/Photon/PhotonVoice/Code/VoiceLogger.cs:67)
Photon.Voice.PUN.PhotonVoiceNetwork:set_Instance (Photon.Voice.PUN.PhotonVoiceNetwork) (at Assets/Photon/PhotonVoice/Code/PUN/PhotonVoiceNetwork.cs:151)
Photon.Voice.PUN.PhotonVoiceNetwork:Awake () (at Assets/Photon/PhotonVoice/Code/PUN/PhotonVoiceNetwork.cs:238)
It looks like this should be normal Unity singleton behaviour - the new version gets destroyed, the old one continues. So why is it generating an error? Is there something else I have to do to make this safe? Or do I have to implement my own singleton scheme to get this to work?
0
Comments
-
Hi @Malcolm,
Thank you for choosing Photon!
Here are the options:
1. ignore the error (optionally comment out error log call or change its logging level)
2. load scenes additively to avoid reloading same scene that contains PhotonVoiceNetwork marked w/ DDOL
3. add PhotonVoiceNetwork to a prefab and remove it from the scene, instead, instantiate it as prefab as soon as game starts and once per game session.0 -
Thanks,
I tried number 3 but it appears that Photon Voice creates a default PhotonVoiceNetwork if there is none in the scene. I guess this is sensible but then I can't use my prefab to set things up the way I want.
I guess I will comment out the error, then I will have to do the same if I update Photon Voice. I hope I remember this :-)0