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. Dismiss Notice

List<List<TimelineAsset>> Populated in Editor Goes Null on Play

Discussion in 'Scripting' started by ippdev, Mar 6, 2021.

  1. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,789
    I have an editor tool that creates a full set of TimelineAssets per section of a show, stores them in a Directory and the show sections get sequenced at runtime. So I load these assets from their respective directories into the runtime component SceneJukeboxSequencer. The List of Lists of TimelineAssets can be seen in the components Inspector field. However when I hit Play the List of Lists goes null. When I come back out of Play it is still null and I cannot reload the sequence back in until I do something like add a new line of code and then the button that populates the List of Lists will reload the sequence so I can again view it as not null in the Inspector.

    Am I assuming correctly that these assets in the directories can be referenced at runtime from the List of Lists? If not why can I populate them in an Editor script? If so why do the List of Lists get set to null immediately on Play? I am using SetSceneDirty as well which seemed to solve other issues with the editor scripts changing things but not updating at runtime.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    I don't think Unity supports lists of lists this way.

    You can make a list of editable (eg,
    [Serializable]
    ) objects, and inside that object have another list.

    I think that's the only way to get nested collections to play nice with the editor inspector.
     
  3. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,789
    I can create nice Lists of List in the Editor Inspector with OdinInspector and [ShowInInspector] attribute. I can even load a List of the Lists into the 103 PlayableDirectors whilst still in Editor mode. Debugging shows the Lists populated each time I click the button in the Editor window that executes that method..but only sometimes do the actual Lists on the runtime component receiving those references populate. I am thinking of workarounds such as creating Scene gameObjects that have one script..the List of TimelineAssets to be loaded for that sequence index. That way the reference will exist in the Hierarchy instead of a Directory. I was also looking at Addressables but that is a learning curve from a quick perusal of the documentation as I can't see how it is done from the Editor and not manually. Regardless I am still in the dark as to why it will null out a populated List when entering Play mode.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    While it's nice that Odin and/or Advanced inspector can show you complicated data types and let you manipulate data beyond what Unity can, I think the
    List<List<T>>()
    limitation is more of a Unity YAML serialization issue. This is kinda borne out by your observations: you can fill them in all day long, but the serializer fails to preserve restore them when you hit play.
     
    Joe-Censored likes this.
  5. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,789
    I think yer correct here. I have the directory refs but GetAssetsAtPath seems to be Editor only. I can somehow script them to be addressables or the simplest is just create GameObject in the Hierarchy and store a list per object and then access the sequence collection from the gameObject component storing the TimelineAsset scene sequence set of that sequencer index. When the sequence changes order I don't have to recreate..just access the same objects in a different order or add or remove the objects as per the sequence changes. Seems clunky but may turn out to be the most elegant.