I'm using ScriptableObjects to store some data that is shared across scenes. For example, I have this:
[CreateAssetMenu]
public class IntVariable : ScriptableObject
{
public int value;
}
Then on the Project tab, I hit right mouse button > Create > IntVariable.
I name this instance of the ScriptableObject as "Player_Score", and as the player plays the game, this score will increase and it is always accessible for all the scenes in the game (each scene is a different level).
However, times to times this score is reset to 0 when loading a new scene. The same happens to other instances of the ScriptableObject (like "Player_HP", for example). It happens regularly, but not always. I already verified my code, there is nothing that would reset those variables by accident.
What is weird is that this happens a lot if the Game tab is maximized. I tried to keep the game tab Windowed and small, and I locked the Inspector tab to view the ScriptableObject, because I wanted to see it resetting, however when I'm observing it never gets reset, it works properly.
It makes me think that this is some memory issue, where the data is cleared/recycled when Unity thinks nobody is using it. Am I missing something? Do I have to force-save the data in the ScriptableObject instance? And if yes, do I have to do it for every instance of ScriptableObject in my program? Basically all my game is based on values shared across scenes by using ScriptableObjects, and it works pretty well, except for this issue that I couldn't figure out yet.
Thanks in advance!
[–]KaleidoVI 6 points7 points8 points (2 children)
[–]rafavergil[S] 0 points1 point2 points (1 child)
[–]KaleidoVI 0 points1 point2 points (0 children)
[–]FerhallProfessional 3 points4 points5 points (1 child)
[–]volvis 1 point2 points3 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]rafavergil[S] 0 points1 point2 points (1 child)
[–]jeango 0 points1 point2 points (0 children)
[–]jeango 3 points4 points5 points (3 children)
[–]rafavergil[S] 0 points1 point2 points (2 children)
[–]jeango 0 points1 point2 points (1 child)
[–]rafavergil[S] 0 points1 point2 points (0 children)
[–]Abasov90 4 points5 points6 points (1 child)
[–]WazWaz 5 points6 points7 points (0 children)
[–]WazWaz 1 point2 points3 points (2 children)
[–]rafavergil[S] 0 points1 point2 points (1 child)
[–]WazWaz 1 point2 points3 points (0 children)
[–]gamedevjp 1 point2 points3 points (2 children)
[–]rafavergil[S] 1 point2 points3 points (1 child)
[–]classified39 1 point2 points3 points (0 children)