Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Where is ScriptableObject data stored on the asset file?

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

  1. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    381
    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! tag:unity3d.com,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: []
    16.  

    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

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    381
    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

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,915
    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.