Search Unity

missing reference exeption when using playerprefs in ondisable

Discussion in 'Documentation' started by halevi, Apr 3, 2022.

  1. halevi

    halevi

    Joined:
    Dec 13, 2020
    Posts:
    35
    i have setting script in my game which control on music and a few more things, the music object and the rest of the references are on other objects in the scene and i grab those references to setting script which it is on the settings object, i save the preferences of the user by playerprefs in ondisable in the setting script , the problem is when i set the player prefs i try to access to reference of music for exemple(to know which value to save) but the object on which the music component is belongs already destroyed and i get missing reference exeption , i have one solution to simlply not refernce in ondisable the music reference itself but rather to reference other varible which get the music value befour ondisable and this varible belong to setting script but it's getting a little cumbersome because I have to create new variables for it , so is there way to set player prefs when the user exit from the game in ondisable and reference to otherobjects so I will not have to create new variables without to get missing reference exeption ? maybe to control on order execution of destroying objects in certain way or somthing else? thanks in advance
     
    Last edited: Apr 4, 2022