Why is my Scriptable Object data missing from the .asset file?

I’m very puzzled by the contents of my Progression.asset file as it exists at the start of this lecture.

Here’s the data I’ve manually entered into my Progression.asset resource (in the Unity Editor):

Yet here’s the contents of the Progression.asset file:

%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: 0}
  m_Enabled: 1
  m_EditorHideFlags: 0
  m_Script: {fileID: 11500000, guid: 8bc293b47323475eac0b92737ea98c3e, type: 3}
  m_Name: Progression
  m_EditorClassIdentifier:

Yep, that’s the full file. No actual data is present at all! Where is the data?

I thought the file is saved - when I reopen Progression.asset in the Editor the data is displayed as per the screenshot above. What’s more, all the game logic using it is working properly.

I do have “Force Text” set for Project Settings > Editor > Asset Serialization.

I’m using Unity 2018.4 on MacOS (I would have used 2018.3 but Rick did say that 2018.4 would probably be OK, but maybe this is one difference?)

Ok, that was really strange. I duplicated Progression.asset and the resulting file does have the data I expect within it. Then I opened the original Progression.asset with my text editor and Unity had written it to disk with the data included. Perhaps Unity was keeping the data in memory only?

I said in my original comment (before I edited it) that I thought that the file was definitely saved, but now I’m not so sure. Is it possible that Unity keeps Scriptable Object data in memory until it needs to write it to disk? I didn’t restart Unity but maybe if I had it would have committed the data to the file.

EDIT: looks like there are some known issues when working with Scriptable Objects - changes are indeed kept in memory and are only written to disk in certain situations - more and more.

Hope this helps anyone else who comes across this.

I’ve done some more experiments with this and it seems, on my system at least, that you can force Unity to sync any pending Scripted Object changes to a file (e.g. before committing to source control) by doing an explicit File > Save Project, even though the project is not marked as “dirty”. If you forget to do this, then it’s really easy to inadvertently miss committing recent SO changes - not a developer-friendly behaviour!

It also means that if Unity crashes (or your power goes out!) any unsaved changes to Scriptable Objects are lost.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms