I start the menu, then I go to the online scene - into battle, then I need to return to the menu after a while, and when I return to the menu, the scene loads and cannot load, along with this, two errors are displayed:
PhotonView ID duplicate found: 999. New: View 999 on RoomManager (scene) old: View 999 on RoomManager (scene). Maybe one wasn’t destroyed on scene load?! Check for ‘DontDestroyOnLoad’. Destroying old entry, adding new.
InvalidOperationException: Duplicate key 999.
I already realized that I need to delete the duplicate RoomManager in the scene, I did it, but it turns out that I need to delete this RoomManager “in advance”…
Please pay attention to this problem… I really need help!
Here is the code:
public static RoomManager Instance; void Awake()
{
DontDestroyOnLoad(gameObject);
Instance = this;
}
2 Answers
2
Hello DIMA_KYST,
I haven’t used Photon myself but I’m pretty sure the idea of using DontDestroyOnLoad is to keep the scene persistent through the entirety of the game life like a singleton, in order word you shouldn’t try to destroy it and recreate it, it should be instantiated only once in the beginning of the game.
Try to rework your game logic to only use one instance of the RoomManager and keep us in touch
I hope it helps
I managed to solve this problem, hooray, I’m happy!!
I accidentally added a line of code for the script that makes the exit from the battle in the menu: <PhotonNetwork.LeaveRoom();
SceneManager.LoadScene(0);> - after that, the menu started loading, then I need to add this code to the RoomManager so that there is only one: <void Awake()
{
RoomManager roomManagers = FindObjectsOfType();
if (roomManagers.Length > 1)
{
Destroy(gameObject);
}
else
{
DontDestroyOnLoad(gameObject);
}
}>
here is the code: public static RoomManager Instance; void Awake() { DontDestroyOnLoad(gameObject); Instance = this; }
– DIMA_KYST