Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Where is ScriptableObject data stored on the asset file?

Discussion in 'Scripting' started by Darkgaze, Sep 1, 2022.

  1. Darkgaze


    Apr 3, 2017
    Very simple question.
    I create a Scriptable Object class that stores an array of data:

    Code (CSharp):
    1. [CreateAssetMenu(fileName = "ScriptableObjTest")]
    2. public class ScriptableObjTest : ScriptableObject
    3. {
    4.     [HideInInspector]
    5.     public float[] values = new float[0];
    6. ...
    When I create it, an .asset is created in the project.

    When I open the asset it contains:

    Code (CSharp):
    1. %YAML 1.1
    2. %TAG !u!,2011:
    3. --- !u!114 &11400000
    4. MonoBehaviour:
    5.   m_ObjectHideFlags: 0
    6.   m_CorrespondingSourceObject: {fileID: 0}
    7.   m_PrefabInstance: {fileID: 0}
    8.   m_PrefabAsset: {fileID: 0}
    9.   m_GameObject: {fileID: 0}
    10.   m_Enabled: 1
    11.   m_EditorHideFlags: 0
    12.   m_Script: {fileID: 11500000, guid: 77da5dc8db2a46b4797932fecca75e77, type: 3}
    13.   m_Name: ScriptableObjTest
    14.   m_EditorClassIdentifier:
    15.   values: []

    So there's a guid of an instance in the scene... a file ID that I suppose points to the .asset file....

    but where's the actual data stored?. where are the contents of the array? isn't the data serialized?
  2. Darkgaze


    Apr 3, 2017
    I was doing it wrong. I was creating the data in OnEnable. which stays there but is not saved.
    If you create the data on the constructor, it is saved in the file.
    migwellian and Olleus like this.
  3. Bunny83


    Oct 18, 2010
    Right. :) So the values should be in the values array you see at the very bottom. Though in your case it's empty. The "m_Script" reference is the reference to the MonoScript instance (the script file itself) that describes this scriptable object / MonoBehaviour.
    Darkgaze likes this.