Hi. I’ve tried to use this function to manually add curve to animation clip via script : SetEditorCurve(AnimationClip clip, EditorCurveBinding binding, AnimationCurve curve); where
binding’s property name would point to a chosen array variable’s index. For example I have a List colorValues = new List(); and assume i have it already populated with colorValues.Add(new Color());
i want to take this with binding.propertyName like “colorValues[0]” or “colorValues[1]” etc. Haven’t found yet any further documentation or evidence of syntax like that to be existing… Anybody knows something more about it? [ Yes it must be stored in a list/array or some sort of container that is expandable and its contents are unknown until i generate them ]
AFAIK that is not possible. The usual way to access array elements in property paths is colorValues.Array.data[0]
in Unity’s strange internal format. However this does not seem to work for animation curve bindings.
One workaround would be to use a simple monobehaviour script for each value so you can link to a proper instance. Though I don’t think this is a great solution ^^. Are you sure you have to create an animationclip? If this is important and you create it procedurally anyways, you can always use just an AnimationCurve and manually evaluate it along with the animation so you are free what you’re doing with the value. Though we don’t know the exact usecase.
Thanks for your answer. So basically main context behind what i am trying to achieve is a script that lists all sprite renderer’s material properties based on gameObject that i put it on. These are shown by serialized property with Custom Editor and applied back to this material [original material that is not shared] with unity function OnValidate(). Everything was fine until i realized these variables stored in lists/arrays doesn’t show in Animation Window => ‘Add Property’ button and i cannot in any way record an animation for that other than by script i guess? If have any idea how could i achieve this or any other approach, please reply. Thanks in advance
I’m sorry I necro the thread without offering a solution
I just found myself in the same situation and I’d like to know if you found something?
I found this, but I’m not able to create elements for the list in Editor if y put the tag [SerializeReference]
Yeah, unfortunately Unity hasn’t provided a good out of the box option to support [SerializeReference]
fields and selecting compatible types.
You could as a quick fix use [ContextMenu]
: https://docs.unity3d.com/ScriptReference/ContextMenu.html and have it added new instances to the collection.
Otherwise you’d need to write a custom inspector.