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

Scriptable Object Field Serialization

Discussion in 'Scripting' started by Figo_Hunter, Jul 29, 2020.

  1. Figo_Hunter

    Figo_Hunter

    Joined:
    Feb 12, 2016
    Posts:
    7
    Is there a way that can serialize a scriptable object field as a serialized property instead of a guid? I found out the TimelineAsset and TrackAsset are both subclass of PlayableAsset which is bascially a ScriptableObject. I wonder how unity serialize TrackAsset field inside the Timeline serialization file without creating a TrackAsset itself and referencing it by guid. Is there anything special in ISerializeCallback functions? Can I do the same thing with the C# script?
     
  2. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    They probably use something like ExpandableAttribute and create the asset in the background.
     
  3. Figo_Hunter

    Figo_Hunter

    Joined:
    Feb 12, 2016
    Posts:
    7
    OK, I think I got it. The TrackAsset and the TimelineAsset are serialized in the exact same file. AssetDatabase.LoadAllAssetsAtPath() gives me the timeline, the tracks and all the animation playable assets. Thus, my assumption is that AssetDatabase.AddObjectToPath can do the job, which can be an alternative to serialize an abstract class.