Search Unity

Custom Object Reference Curve

Discussion in 'Animation' started by ribbanya, Jan 23, 2020.

  1. ribbanya

    ribbanya

    Joined:
    Feb 28, 2019
    Posts:
    9
    Hi, I'm basically trying to do exactly this:
    https://forum.unity.com/threads/animate-custom-type-property.589663/#post-3936382

    But there are no answers.

    To summarize, I have a custom component, and it has a SerializeField pointing to a custom ScriptableObject.

    Here's my code:

    Code (CSharp):
    1. var anim = AssetDatabase.LoadAssetAtPath<AnimationClip>(
    2.     "Assets/MyAnimationClip.anim");
    3. var binding = EditorCurveBinding.PPtrCurve("", typeof(MyComponent), "_myField");
    4. var keyframe = AssetDatabase.LoadAssetAtPath<MyScriptableObject>(
    5.     "MyScriptableObjectAsset.asset");
    6. var array = new[]
    7. {
    8.     new ObjectReferenceKeyframe
    9.     {
    10.         time = 0,
    11.         value = keyframe
    12.     },
    13.     new ObjectReferenceKeyframe
    14.     {
    15.         time = 10/60f,
    16.         value = null
    17.     },
    18.     new ObjectReferenceKeyframe
    19.     {
    20.         time = 20/60f,
    21.         value = keyframe
    22.     },
    23.     new ObjectReferenceKeyframe
    24.     {
    25.         time = 30/60f,
    26.         value = null
    27.     }
    28. };
    29. AnimationUtility.SetObjectReferenceCurve(anim, binding, array);
    30. AssetDatabase.SaveAssets();
    31. AssetDatabase.Refresh();
    The result is that I can see the keyframes in the editor, but more often than not it says the component is "missing" (it's not), and no matter what it will never change the given property.

    Are sprites somehow hardcoded in the engine or something? I knew the Animation editor window was limited in what it could do, but this is really disappointing.

    Alternatively to this, is there a way to set an ObjectReferenceCurve onto a custom PlayableAsset?
     
    ModLunar likes this.
  2. ribbanya

    ribbanya

    Joined:
    Feb 28, 2019
    Posts:
    9
    anthonyalvo25, ModLunar and sabojako like this.
  3. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    Weird, I've never used
    EditorCurveBinding.PPtrCurve(...)
    before.
    For example, I've only used something like this, regardless of whether or not the curve was an objectReference or not:

    Code (CSharp):
    1. new EditorCurveBinding() {
    2.     path = "Your/Transform/Path",
    3.     propertyName = "m_Sprite",
    4.     type = typeof(SpriteRenderer)
    5. };
    I think this should work, but let me know if it doesn't.