I create an instance of ScriptableObject onto my disk as an .asset file.
Then I planned to use that file at runtime so I create a public variable in one of my component as that ScriptableObject type so the slot would show up in the inspector. I then drag my .asset file to that slot and I can use its value as soon as I enter play mode and I see changes immediately applied to my .asset file by clicking on the file in my asset tree and I see the Inspector showing the changed value that my script changes.
However, the actual data on disk havenāt change yet! I tried opening that file on my disk (I use āForce Textā serialization so I can read it) and the value in that file is not like in the inspector! I can enter play mode and exit as many time as I wanted and the value is saved across plays but never to my file in disk. The real problem starts when I closed unity and open again, the value has gone because it was never saved to disk.
If I push Ctrl+D to duplicate the file, the Inspector of new file will show the value on disk of original file, not the updated ones in the inspector. Supporting the evidence that the value on disk is not getting updated.
BUT one way that I got it to finally update is, I changed one of the field that show up in .asset inspector by hand in editor mode. Then the moment I close Unity the file will be updated! I wondered why when I used the script to change values (adding Note objects to the list, as seen below) the file refuse to update when I close unity and simply discarding changes? (Of course the ideal solution is I want it to save immediately, not when closing unity.)
Can someone help me so I can update changes to disk?
Here is my class hierarchy. I got it to save when closing Unity by, for example, changing the ābpmā number to something else in the .asset file inspector and close Unity.
public class Simfile : ScriptableObject {
public string songName;
public string artist;
public string noteCharter;
public AudioClip musicFile;
public int bpm;
public float offset;
[SerializeField] Chart easyChart;
[SerializeField] Chart normalChart;
[SerializeField] Chart expertChart;
.
.
.
[System.Serializable]
public class Chart
{
Note focusedNote = null;
[SerializeField] int laneCount;
[SerializeField] int noteCount;
[SerializeField] public List<Note> notes;
.
.
.
[System.Serializable]
public class Note {
[SerializeField] float position;
[SerializeField] float absolutePosition;
[SerializeField] int specialNote;
[SerializeField] int lane;
[SerializeField] float nextLinkAbsolutePosition;
[SerializeField] int nextLinkLane;
[SerializeField] float prevLinkAbsolutePosition;
[SerializeField] int prevLinkLane;
.
.
.
Thank you