- Home /
In Timeline/custom Playables, how to get the original/current values of bound object when creating a new clip?
I followed https://blogs.unity3d.com/2018/09/05/extending-timeline-a-practical-guide/ and I'm trying to create a blendable asset as described in section (4) of the doc.
In my PlayableAsset
subclass, I override CreatePlayable()
. In the original sample code, there's a template
field for the initial value. How do I get the 'original' values (or even better, the current values at the point in the timeline where this clip is being created) of the bound target?
Even in the sample, when you create a new clip ( Mixer_LightControlTrack
/ Mixer_LightControlAsset
), the actual target object gets its colour and intensity set to black and 0. Not so bad when they are simple to correct. Really painful when you have lots of data!
E.g. I'm animating a multi-part line which has several points. I wish to animate those points each frame. I create a new track, bind it to my game object's line (the gameobject has several such lines). I then right click and create a new asset.
p.s. sorry if I'm using the wrong terms/whatever here -- I'm very much still trying to wrap my head around extending Timeline so might be asking the wrong question!
Answer by seant_unity · Apr 15, 2020 at 02:41 PM
The simplest way to do this is inside ProcessFrame, copy the original values from the trackBinding the first time you see it and use those as defaults
i if (!trackBinding) return; if (!firstFrame) { defaultIntensity = trackBinding.intensity; defaultColor = trackBinding.color; firstFrame = true; } finalIntensity = defaultIntensity; finalColor = defaultColor;
note that you would need to add firstFrame, defaultIntensity and defaultColor as private members of the LightControlMixerBehaviour class.
First: thanks for this suggestion. I tried this however it doesn't answer the original question -- it didn't let me assign the values to the new clip. It did act as a starting place for me to solve the problem though! I don't know whether this is a huge kludge and/or going to break due to any tiny change. I'll post it as an answer unless you have a better approach...
I use the value as you describe, check each input as I'm evaluating them, detect it they have not been initialised and then assign the current values to them. Sadly merely assigning to the 'data object' (i.e. Anim_LightControlBehaviour
in the sample) doesn't persist so I ended up recording the owning clip ( Anim_LightControlAsset
in the sample) into the data object then using that reference to assign through the data object to the owning clip to assign the values to the template!?!? Uuuuugggggly! But it does work!
So I now see my values appear in the template
field in the Inspector and can tweak them there to create animations. Hopefully you'll suggest a better answer and I can rip this rubbish out and mark that new one as correct :) Thanks again!