- Home /
MissingReferenceException after loading scene.
I'm making a game with DarkRift API, first the player has to create the server, then the host needs to wait for other players in a lobby before starting the game. When a player connects to a server, the active scene for that player changes with SceneManager.LoadScene(1, LoadSceneMode.Single)
(I also tried adding SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(1))
after that line).
Here's the problem, if a player leaves the server, the scene of that player changes to the first one ( SceneManager.LoadScene(1, LoadSceneMode.Single)
), but if he tries to join again to a server, in the moment when he receives all the DarkRiftAPI messages to sync all the stuff, the script needs to change the texts with the info, but it says that the Text has been destroyed.
I putted a Debug.Log
of the Texts, and in the moment when all the messages are received, the Texts are null, but after the player stops receiving, the Texts are normal.
Basically, the first time a player joins a server, everything is normal, but if he disconnects and try to connect to other server, that happens.
I tried to change the Script Execution Order but it doesn't fixed it.
EDIT: I believed when I load the scene again, the variables are the same before the scene unloaded, so in the first call the variables aren't the new Objects, but if I put a Debug.Log
on Start, the object exists, but on any other void, the object is null.
Answer by Sosin · Dec 27, 2016 at 11:14 PM
I think i found the problem (very dumb).
Every Update on the menu, I was testing if the player was connected to a server, if it was, change the scene. But because I was testing it every Update, for some reason the test ( DarkRiftAPI.isConnected
) executed twice, making the scene to load two times.
EDIT: Nope, it wasn't the problem, still the same, I believed when I load the scene again, the variables are the same before the scene unloaded, so in the first call the variables aren't the new Objects, but if I put a Debug.Log
on Start, the object exists, but on any other void, the object is null.
Your answer
Follow this Question
Related Questions
MissingReferenceException after loading a scene, missing object of type text and button. 0 Answers
GameManager trying to access method from deleted GameManager via the InvokeRepeating() function 0 Answers
How to play Animation of a button first, THEN only proceeding to the next scene ? 3 Answers
Strange Errors when building game 0 Answers
Destroyed Object Error 2 Answers