- Home /
MissingReferenceException on SceneLoading
So I have this simple Script on my UI:
public class SaveAndLoad : MonoBehaviour
{
[SerializeField] InventoryObject[] invenToriesToLoad;
private void Start()
{
for (int i = 0; i < inventoriesToLoad.Length; i++)
{
inventoriesToLoad[i].Load();
}
}
}
I have it attached to a GameObject in two different scenes. In the first one (Menu) there is an avilableAttacks and a EquippedAttacks Inventory. In the second scene (Game) there is just an EquippedAttacks Inventory. when entering into PlayMode individually into the scenes, the Inventories load without a problem. But when I switch the scene from the menu to the Game with following Code I get a "MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it"
public class SceneSwitcher : MonoBehaviour
{
public void LoadGame()
{
SceneManager.LoadScene(0);
}
}
I have a feeling it's an error with how I switch my scene and that the old scene doesn't get unloaded correctly or something so that it tries to execute the code on the old scene because I don't get this error whe not switching the scenes. Any ideas? Thank you!
Your answer
Follow this Question
Related Questions
animation does not work when one clone got destroy unity 1 Answer
Detecting and setting active a child object using VRTK 0 Answers
Scripted SetTextureOffset not working after switching to Universal Render Pipeline 1 Answer
How to have an enemy spawn a certain distance behind the player 1 Answer
Application.isPlaying returning true when I exit play mode 0 Answers