Exposed reference for data in List<>

Hi, I am writing my custom playable track for timeline, and I’m stuck with exposed references thing.

I get the idea from the example custom tracks available online, how to connect one variable in PlayableBehaviour script with exposed reference in Clip script (PlayableAsset, ITimelineClipAsset) in CreatePlayable method.

[Serializable]
public class MyCustomBehaviour : PlayableBehaviour
{
    public Transform myTransform;
}

[Serializable]
public class MyCustomClip : PlayableAsset, ITimelineClipAsset
{
    public MyCustomBehaviour data = new MyCustomBehaviour();
    public ExposedReference<Transform> exposedTransform;

    public ClipCaps clipCaps
    {
        get { return ClipCaps.None; }
    }

    public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    {
        var playable = ScriptPlayable<MyCustomBehaviour>.Create(graph, data);

        MyCustomBehaviour clone = playable.GetBehaviour();
        clone.myTransform = exposedTransform.Resolve(graph.GetResolver());

        return playable;
    }
}

But, how to expose variable that is inside complex data structure, like this:

[Serializable]
public class MyCustomBehaviour : PlayableBehaviour
{
    [Serializable]
    public class MyCustomClass
    {
        //How to expose this variable?
        public Transform myTransform;
    }

    public List<MyCustomClass> myCustomClassesList = new List<MyCustomClass>();
}

I have the same problem. I need a list of exposed references that is shown in the inspector but it does not work. For example, in the PlayableAsset I made I have a public variable of type List<ExposedReference> which I expected to be shown like any other list in the inspector, but it doesn’t. It just doesn’t want to get serialized as soon as it’s in a list. I tried to look into drawing a custom inspector for lists of exposed references but it became a bit complicated in the fact that it involved ExposedReference… I hope someone who know how to fix this. This is a big problem for the asset I’m currently working on.

I hava the same problem, i think this’s a bug or defect for Timeline.

It’s a known issue that arrays and list of exposed references don’t serialize and won’t work correctly.

^ is it fixed in the new version?

No, have same issue on 2017.3.0.

Hey, to workaround this problem use this approach.

[Serializable]
public class MyThing
{
[SerializeField]
public ExposedReference thing;
}

public class TestSerializable : MonoBehaviour
{
public List myThingList;
}

3 Likes

I use wrapper for ExposedReference and then make array of wrappers as workaround

[Serializable]
public class ExposedReferenceHolder<T> where T : Object
{
  public ExposedReference<T> ExposedReference;
}

[Serializable]
public class ExposedCollider : ExposedReferenceHolder<Collider>
{
}

[Serializable]
public class ColliderArrayBehaviour : PlayableBehaviour
{
  public ExposedCollider[] TrackingObjects;
}
8 Likes

Yeah so I’ve basically wasted the last two days trying to come up with workarounds for this. The desire to use arrays in Timeline clips isn’t something that should be considered unusual or esoteric. I realize that this is mainly due to the serialization system but it really should be addressed and made to work out of box. I’m now stuck having to use dozens of clips where one would suffice if it only supported arrays of references properly.

That’s a clever workaround. A bit clunky in the inspector but workable nonetheless. Hopefully we won’t have to do this in 2020 as it will have native support for seralising generics.

I just ran into this in unity 2020.3.1f1
Is it fixed in a newer version?

1 Like

Doing that in 2022.

1 Like