Search Unity

error CS0117: 'AnimationMode' does not contain a definition for 'GetCurveBindings'

Discussion in 'Scripting' started by carlosdaniel369, Nov 15, 2019.

  1. carlosdaniel369

    carlosdaniel369

    Joined:
    Nov 6, 2019
    Posts:
    5
    Library\PackageCache\com.unity.timeline@1.2.6\Runtime\Utilities\AnimatorBindingCache.cs(91,40): error CS0117: 'AnimationMode' does not contain a definition for 'GetCurveBindings'



    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Playables;
    5. using UnityEngine.Timeline;
    6. using UnityEditor;
    7.  
    8. namespace UnityEngine.Timeline
    9. {
    10.     /// <summary>
    11.     /// Animator to Editor Curve Binding cache. Used to prevent frequent calls to GetAnimatorBindings which can be costly
    12.     /// </summary>
    13.     class AnimatorBindingCache
    14.     {
    15.         public const string TRPlaceHolder = "TransformTR";
    16.         public const string ScalePlaceholder = "TransformScale";
    17.  
    18.         struct AnimatorEntry
    19.         {
    20.             public int animatorID;
    21.             public bool applyRootMotion;
    22.             public bool humanoid;
    23.         }
    24.  
    25.         class AnimatorEntryComparer : IEqualityComparer<AnimatorEntry>
    26.         {
    27.             public bool Equals(AnimatorEntry x, AnimatorEntry y) { return x.animatorID == y.animatorID && x.applyRootMotion == y.applyRootMotion && x.humanoid == y.humanoid; }
    28.             public int GetHashCode(AnimatorEntry obj) { return HashUtility.CombineHash(obj.animatorID, obj.applyRootMotion.GetHashCode(), obj.humanoid.GetHashCode()); }
    29.             public static readonly AnimatorEntryComparer Instance = new AnimatorEntryComparer();
    30.         }
    31.  
    32.         readonly Dictionary<AnimatorEntry, EditorCurveBinding[]> m_AnimatorCache = new Dictionary<AnimatorEntry, EditorCurveBinding[]>(AnimatorEntryComparer.Instance);
    33.         readonly Dictionary<AnimationClip, EditorCurveBinding[]> m_ClipCache = new Dictionary<AnimationClip, EditorCurveBinding[]>();
    34.  
    35.         private static readonly EditorCurveBinding[] kEmptyArray = new EditorCurveBinding[0];
    36.         private static readonly List<EditorCurveBinding> s_BindingScratchPad = new List<EditorCurveBinding>(1000);
    37.  
    38.         public AnimatorBindingCache()
    39.         {
    40.             AnimationUtility.onCurveWasModified += OnCurveWasModified;
    41.         }
    42.  
    43.         public EditorCurveBinding[] GetAnimatorBindings(GameObject gameObject)
    44.         {
    45.             if (gameObject == null)
    46.                 return kEmptyArray;
    47.  
    48.             Animator animator = gameObject.GetComponent<Animator>();
    49.             if (animator == null)
    50.                 return kEmptyArray;
    51.  
    52.             AnimatorEntry entry = new AnimatorEntry()
    53.             {
    54.                 animatorID = animator.GetInstanceID(),
    55.                 applyRootMotion = animator.applyRootMotion,
    56.                 humanoid = animator.isHuman
    57.             };
    58.  
    59.             EditorCurveBinding[] result = null;
    60.             if (m_AnimatorCache.TryGetValue(entry, out result))
    61.                 return result;
    62.  
    63.             s_BindingScratchPad.Clear();
    64.  
    65.             // Replacement for AnimationMode.GetAnimatorBinding - this is faster and allocates kB instead of MB
    66.             var transforms = animator.GetComponentsInChildren<Transform>();
    67.             foreach (var t in transforms)
    68.             {
    69.                 if (animator.IsBoneTransform(t))
    70.                     s_BindingScratchPad.Add(EditorCurveBinding.FloatCurve(AnimationUtility.CalculateTransformPath(t, animator.transform), typeof(Transform), TRPlaceHolder));
    71.             }
    72.  
    73.             var streamBindings = AnimationUtility.GetAnimationStreamBindings(animator.gameObject);
    74.             UpdateTransformBindings(streamBindings);
    75.             s_BindingScratchPad.AddRange(streamBindings);
    76.  
    77.             result = new EditorCurveBinding[s_BindingScratchPad.Count];
    78.             s_BindingScratchPad.CopyTo(result);
    79.             m_AnimatorCache[entry] = result;
    80.             return result;
    81.         }
    82.  
    83.         public EditorCurveBinding[] GetCurveBindings(AnimationClip clip)
    84.         {
    85.             if (clip == null)
    86.                 return kEmptyArray;
    87.  
    88.             EditorCurveBinding[] result;
    89.             if (!m_ClipCache.TryGetValue(clip, out result))
    90.             {
    91.                 result = AnimationMode.GetCurveBindings(clip);
    92.                 UpdateTransformBindings(result);
    93.                 m_ClipCache[clip] = result;
    94.             }
    95.  
    96.             return result;
    97.         }
    98.  
    99.         private static void UpdateTransformBindings(EditorCurveBinding[] bindings)
    100.         {
    101.             for (int i = 0; i < bindings.Length; i++)
    102.             {
    103.                 var binding = bindings[i];
    104.                 if (AnimationPreviewUtilities.IsRootMotion(binding))
    105.                 {
    106.                     binding.type = typeof(Transform);
    107.                     binding.propertyName = TRPlaceHolder;
    108.                 }
    109.                 else if (typeof(Transform).IsAssignableFrom(binding.type) && (binding.propertyName.StartsWith("m_LocalRotation.") || binding.propertyName.StartsWith("m_LocalPosition.")))
    110.                 {
    111.                     binding.propertyName = TRPlaceHolder;
    112.                 }
    113.                 else if (typeof(Transform).IsAssignableFrom(binding.type) && binding.propertyName.StartsWith("m_LocalScale."))
    114.                 {
    115.                     binding.propertyName = ScalePlaceholder;
    116.                 }
    117.                 bindings[i] = binding;
    118.             }
    119.         }
    120.  
    121.         public void Clear()
    122.         {
    123.             m_AnimatorCache.Clear();
    124.             m_ClipCache.Clear();
    125.         }
    126.  
    127.         void OnCurveWasModified(AnimationClip clip, EditorCurveBinding binding, AnimationUtility.CurveModifiedType modification)
    128.         {
    129.             m_ClipCache.Remove(clip);
    130.         }
    131.     }
    132. }
    133. #endif
    134.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,582
    Take a look at the documentation for Unity's GetCurveBindings()... I think you'll be surprised to find which object it actually lives on, an object you're already familiar with above. :)
     
  3. noclew

    noclew

    Joined:
    Jun 10, 2016
    Posts:
    12
    What kind of answer is this? GetCurveBinding belongs to AnimationUtility, and the op asks why it appears in a runtime script belonging to AnimationMode. Why don't you just give hime the answer?
     
  4. carlosdaniel369

    carlosdaniel369

    Joined:
    Nov 6, 2019
    Posts:
    5
    I give up unity because of this, people think you and a teacher in programming
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,582
    If you google something for someone, you teach them one thing.

    If you teach them how to google, they can teach themselves everything.

    In the specific case above, if you type the name of the identifier into google, the first hit is the actual answer to your question. Google is amazing. Embrace it.
     
    palex-nx and THHamiltonSmith like this.
  6. FailureFactory

    FailureFactory

    Joined:
    May 11, 2017
    Posts:
    1
    I came here using google, only to find the result was a guy telling me to use google. This answer was worse than nothing.
     
  7. amk1855

    amk1855

    Joined:
    Mar 29, 2017
    Posts:
    2
    And that, my friend, is called "recursion"
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,582
    To understand recursion, you must first understand recursion.
     
    Ermiq likes this.
  9. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    6,180
    It's a perfect answer. From the proverb to give vs teach.
     
    Kurt-Dekker likes this.
  10. WilliamNHarvey

    WilliamNHarvey

    Joined:
    Jul 23, 2018
    Posts:
    2
    can one of you just actually answer the question lol... this is the first result on google
     
  11. Rupert-NerdDayGames

    Rupert-NerdDayGames

    Joined:
    Sep 12, 2015
    Posts:
    4
    Open Package Manager and downgrade Timeline to the verified version.
     
    daveseidman1 likes this.
  12. Ermiq

    Ermiq

    Joined:
    May 1, 2018
    Posts:
    7
    Just like many other similar errors, it may occur when the project contains some deprecated code from older versions of Unity. If you search for `GetCurveBindings` in Unity API, you'll find out that it now belongs to `AnimationUtility`: https://docs.unity3d.com/ScriptReference/AnimationUtility.GetCurveBindings.html

    Double click on the error in console, it should open the line of code that caused the error in your code editor. And try to change `AnimationMode` to `AnimationUtility`.
     
    nhimsovichea18 and Sergey-Leluk like this.
  13. Grootloops

    Grootloops

    Joined:
    Nov 16, 2016
    Posts:
    3
    Doing so, will result in new errors.

    This, also results in new errors.
     
  14. minism

    minism

    Joined:
    Feb 11, 2016
    Posts:
    2
    This thread is the most spectacular failure of help I've ever seen :p
     
  15. noclew

    noclew

    Joined:
    Jun 10, 2016
    Posts:
    12
    Try updating the problematic package, the timeline in this case. It solved my problem.
     
  16. noclew

    noclew

    Joined:
    Jun 10, 2016
    Posts:
    12
    What makes you think that people want to be taught when they post a short question like this? Also, do you really think that checking the documentation will give OP meaningful knowledge to this problem?

    People have different levels of expertise, and an easy question for you may not be that easy for others. If you are tired of answering easy questions every time, you can just ignore them. You are not obliged to answer them, and there is no need to play newbies with another riddle. I am amazed that this reply was posted by a Unity person.
     
    DouglasFiorenza likes this.
  17. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    6,180
    A much better approach is to lead the person into the answer so they know how to better address similar questions in the future and empower them to solve their own problems moving forward. Yes, it takes a few more steps on behalf of the user, I get that. I purposely answer questions just like this every single time. It's an investment into their ability to better solve problems they will run into moving forward. It saves their time and effort in the long run, and mine.
     
  18. noclew

    noclew

    Joined:
    Jun 10, 2016
    Posts:
    12
    I do not object to your textbook opinion. When one needs something to eat, it is usually better to teach him how to catch a fish than to give him a fish. However, it is not always the case. Things get worse when the one only needs one fish for one-time use or when the teacher is just bad at teaching. In this thread, I personally see the second case here. All that the first responder said was to check the documentation of GetCurveBindings, which will lead to the fact that it belongs to AnimationUtility. However, knowing it does not help solve the problem, and I do not think that OP didn't check it. It is even stated directly in the error message. In my guess, OP updated his project with a new version of Unity, but he did not update the Timeline package. If that was the case, the solution is to update his Timeline package via Package Manager. However, this solution could be sometimes opaque to newbies, like me, because the Timeline package is included in the project by default, and the first responder's comment only adds another riddle on it.

    When we know something that someone does not, we tend to teach what we know. It is productive and healthy behavior. However, not everyone needs to be a teacher, especially when he/she is not good at teaching. Many times, I see people saying that they are teaching how to catch a fish. However, if it is not done properly, it is even worse than just handing over a fish.
     
    Last edited: Dec 14, 2019 at 10:44 AM
    DouglasFiorenza likes this.
  19. noclew

    noclew

    Joined:
    Jun 10, 2016
    Posts:
    12
    I am sorry, but you taught nothing meaningful. Embrace it.