Hi guys,
After reloading a scene I have an error when one of my script tries to call a method on a public property it has which is another script inside another game object in the scene. This public property is set by simply drag & drop the game object which contains the target script directly in the editor.
I reload the scene like this : SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex,LoadSceneMode.Single);
When the error occurs I can see that :
- the public property it’s not null, it’s still references the script in the game object in the scene
- the game object in the scene still exists and the targeting script too
The error message is :
MissingReferenceException: The object of type ‘Rules’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
I do not manually destroy the reference neither the game object which contains the targeting script. Moreover, when I reload the scene I expect everything to get back to their default state and for what I can see it’s the case. So I don’t understand why I’ve got this error.
Any help is welcomed
Thanks