Search Unity

Question Set Editor curve binding property name that is in array/list

Discussion in 'Scripting' started by Indie_Core, Feb 12, 2022.

  1. Indie_Core

    Indie_Core

    Joined:
    Jun 14, 2021
    Posts:
    6
    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<Color> colorValues = new List<Color>(); 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 ]
     
  2. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,979
    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.

    People have been here before.
     
  3. Indie_Core

    Indie_Core

    Joined:
    Jun 14, 2021
    Posts:
    6
    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 :)
     
    Last edited: Feb 12, 2022
  4. Ga2Z

    Ga2Z

    Joined:
    Feb 16, 2012
    Posts:
    68
    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]

    https://forum.unity.com/threads/is-...s-in-an-array-in-the-animation-window.518707/
     
  5. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,812
    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.
     
    Ga2Z and Bunny83 like this.